Shazam
09-15-2005, 06:58 PM
Hey everybody!
Well I got this code from your website. It tansfers files from one hard drive to another. Can it be modified to transfer all files except the recent file that it was saved to that folder ? If that can be done I would like another code that it will transfer all files except the last 2 recent files that was saved to that folder.
Thanks!
Option Explicit
Option Compare Text
Sub MoveFiles()
Dim myFile As String
Dim oldName As String
Dim newName As String
Dim FileType As String
oldName = "C:\August\" 'This is the original folder
newName = "D:\Test" 'This is the new folder - will be created with the MkDir Statement
FileType = "xls" 'Enter File Type to be moved
'e.g. xls, xl*, doc, do*, or * for all files
On Error Resume Next
MkDir newName 'create a new folder based on the path for the variable 'newName'
myFile = Dir(oldName & "\*." & FileType) 'not restricted to xls files, could also be Word documents etc
Do Until myFile = "" 'until there are no files left
Name oldName & "\" & myFile As newName & "\" & myFile
myFile = Dir 'calls Dir Function again without changing the Path
Loop
End Sub
Well I got this code from your website. It tansfers files from one hard drive to another. Can it be modified to transfer all files except the recent file that it was saved to that folder ? If that can be done I would like another code that it will transfer all files except the last 2 recent files that was saved to that folder.
Thanks!
Option Explicit
Option Compare Text
Sub MoveFiles()
Dim myFile As String
Dim oldName As String
Dim newName As String
Dim FileType As String
oldName = "C:\August\" 'This is the original folder
newName = "D:\Test" 'This is the new folder - will be created with the MkDir Statement
FileType = "xls" 'Enter File Type to be moved
'e.g. xls, xl*, doc, do*, or * for all files
On Error Resume Next
MkDir newName 'create a new folder based on the path for the variable 'newName'
myFile = Dir(oldName & "\*." & FileType) 'not restricted to xls files, could also be Word documents etc
Do Until myFile = "" 'until there are no files left
Name oldName & "\" & myFile As newName & "\" & myFile
myFile = Dir 'calls Dir Function again without changing the Path
Loop
End Sub