Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move files based on Modified Date

Status
Not open for further replies.

ba4crm

Technical User
Dec 19, 2003
92
US
I have customer ids as the folder names. Each folder has a number of text files. Files with a modified date of 6/1/10 or less need to be moved to a zip file called "Jan-June.zip". The zip file will reside in a differnt folder, called "2010", which will reside under the customer's main folder. Neither the 2010 folder or the zip folder exist.

I found the following source code from and tried to modify it a little bit.
However, the code is picking up all the files regardless of the modified date.
I also need help with looping through the customer folders to execute this for all the folders.

Code so far:
*************************************************
Private Function MoveFiles()

Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFill As String, strFolderPath As String


strFolderPath = "C:\Source\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files

For Each objF1 In objFiles
If objF1.DateCreated > 2 / 1 / 2010 Then
objFS.MoveFile strFolderPath & objF1.Name, "C:\Destination\"

End If
Next

Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
End Function
**************************************************

Thank you
 
DateCreated is not the same as DateModified, but if that is what you want, you need a date, say:


If objF1.DateCreated > DateSerial(2010, 1, 31) Then


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top