Copying files

  • Thread starter Thread starter Sammy8932
  • Start date Start date
S

Sammy8932

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!
 
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
 
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
 
That worked. Thanks Jason!

Jason said:
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
 
Thanks for the reply John. This wouldn't work for me as there would be .html
files in the final folder that I need.
 
Back
Top