Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2007

Tip: Looking for answers? Try searching our database.

Copying files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sammy8932 - 19 Jan 2007 16:21 GMT
I need to copy all files not having an .html extension from one folder to
another folder.  What's the best/easiest way to do this?

Thanks!
Jason Lepack - 19 Jan 2007 20:12 GMT
This code is all untested but it should do something like what you
want.  Note that filecopy will not create backups, if there is another
file with the same name in the new directory it will overwrite it.
Also, Kill removes the file ocmpletely, once it's dead, it's gone.

***Make backups before testing any of this.
***Look up any of the functions that you don't understand.

dim olddir as string, newdir as string, strfile as string

olddir = path to the folder you're copying from
newdir = path to the folder you're moving to

strfile = dir(olddir & "*.*")
do while len(strfile) > 0
  if not strfile like "*.html" then
     filecopy olddir & strfile, newdir & strfile
     kill olddir & strfile
  end if
  strfile = dir()
loop

Cheers,
Jason Lepack

> I need to copy all files not having an .html extension from one folder to
> another folder.  What's the best/easiest way to do this?
>
> Thanks!
Sammy8932 - 22 Jan 2007 18:48 GMT
That worked.  Thanks Jason!

>This code is all untested but it should do something like what you
>want.  Note that filecopy will not create backups, if there is another
[quoted text clipped - 25 lines]
>>
>> Thanks!
John Nurick - 19 Jan 2007 21:54 GMT
The laziest is to shell out twice, first time to COPY or XCOPY all the
files to the new folder, second time to delete *.html.

After that, use Dir(), roughly like this:

 Dim OldFolder As String
 Dim NewFolder As String
 Dim FileName As String

 'maybe check that the folders exist
 'and that we have permission to write files in the destination
 ...

 'get to work
 FileName = Dir(OldFolder & "\*.*")
 Do While Len(FileName) > 0
   If Right(FileName, 5) = ".html" Then
     'BTW, what about .htm files?

     'do we need to check if there's already a file
     'in the destination folder?

     FileCopy blah blah 'at last!
    End If
   FileName = Dir()     'ready for the next time round
 Loop

>I need to copy all files not having an .html extension from one folder to
>another folder.  What's the best/easiest way to do this?
>
>Thanks!

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Sammy8932 - 22 Jan 2007 18:49 GMT
Thanks for the reply John.  This wouldn't work for me as there would be .html
files in the final folder that I need.

>The laziest is to shell out twice, first time to COPY or XCOPY all the
>files to the new folder, second time to delete *.html.
[quoted text clipped - 32 lines]
>
>Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.