spellm
asked on
How do I copy files created on a selected date?
I would like to have a script that prompts a user for a date, then copies files from c:\backup ("ST*.txt" & "LR*.txt") created on the user supplied date to c:\logs_win\wms_data
Ideally, the user could type in the date, or click on an icon to bring up a calendar date selector.
Thanks,
Mike
Ideally, the user could type in the date, or click on an icon to bring up a calendar date selector.
Thanks,
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Like this:
Sub CopyFiles()
Dim TheDate As Date
Dim fso As Scripting.FileSystemObject
Dim SourceFld As Scripting.Folder
Dim fil As Scripting.File
Dim Counter As Long
Const DestFldPath As String = "c:\logs_win\wms_data\"
TheDate = InputBox("Enter creation date", "File Date", Format(Now, "d mmm yyyy"))
Set fso = New Scripting.FileSystemObject
Set SourceFld = fso.GetFolder("c:\backup")
Set DestFld = fso.GetFolder("c:\logs_win \wms_data" )
For Each fil In SourceFld.Files
If UCase(fil.Name) Like "ST*.TXT" Or UCase(fil.Name) Like "LR*.TXT" Then
If Format(TheDate, "d mmm yyyy") = Format(fil.DateCreated, "d mmm yyyy") Then
fil.Copy DestFldPath & fil.Name
Counter = Counter + 1
End If
End If
Next
Set fil = Nothing
Set SourceFld = Nothing
Set fso = Nothing
MsgBox "Done; copied " & Counter & " files"
End Sub
Patrick
Sub CopyFiles()
Dim TheDate As Date
Dim fso As Scripting.FileSystemObject
Dim SourceFld As Scripting.Folder
Dim fil As Scripting.File
Dim Counter As Long
Const DestFldPath As String = "c:\logs_win\wms_data\"
TheDate = InputBox("Enter creation date", "File Date", Format(Now, "d mmm yyyy"))
Set fso = New Scripting.FileSystemObject
Set SourceFld = fso.GetFolder("c:\backup")
Set DestFld = fso.GetFolder("c:\logs_win
For Each fil In SourceFld.Files
If UCase(fil.Name) Like "ST*.TXT" Or UCase(fil.Name) Like "LR*.TXT" Then
If Format(TheDate, "d mmm yyyy") = Format(fil.DateCreated, "d mmm yyyy") Then
fil.Copy DestFldPath & fil.Name
Counter = Counter + 1
End If
End If
Next
Set fil = Nothing
Set SourceFld = Nothing
Set fso = Nothing
MsgBox "Done; copied " & Counter & " files"
End Sub
Patrick
ASKER
Great! Thanks a lot.
ASKER