
Find a copy a file with File.Copy method
I have a
VBScript that I use to parse all log the files in a directory to
find the log file created yesterday (using DateCreated property). The script
currently zips the logs, but I want to change that.
Once the file has been found, I want to copy it locally to a different
directory and rename it in the process. I know how to use File.Copy when I
already know file name, but how to I tell File.Copy to copy the file when
the I can't give it an explicit name??
(the log file has a different name every day)
Here is the code
On error resume next
Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set RootFolder = FileSystem.GetFolder(RootDir)
RootDir = Wscript.Arguments(0)
Set SubFiles = RootFolder.Files
For Each File in SubFiles
SourceFile = File.DateLastModified
If SourceFile = ((Date()) -2) Then TargetFile.Copy "c:\DestFile.csv",1
Next