Reputation: 31
I'm trying to copy files from a directory where the last modified date is within 24hours of the current date. I'm using a wildcard in the filepath as it changes every day I'm using;
option explicit
dim fileSystem, folder, file
dim path
path = "d:\x\logs"
Set fileSystem = CreateObject("Scripting.FileSystemObject")
Set folder = fileSystem.GetFolder(path)
for each file in folder.Files
If DateDiff("d", file.DateLastModified, Now) < 1 Then
filesystem.CopyFile "d:\x\logs\apache_access_log-*", "d:\completed logs\"
WScript.Echo file.Name & " last modified at " & file.DateLastModified
end if
next
Unfortunately this seems to be copying all files, and not just the recently modified ones. Can anyone point me in the right direction?
many thanks
Martin.
Upvotes: 3
Views: 16103
Reputation: 426
Change line to:
filesystem.CopyFile file, "d:\completed logs\"
You were copying every file in the directory as soon as one file matched your criteria
Upvotes: 1
Reputation: 25386
It looks like you are copying all files if any file satisfies the DateDiff
comparison.
Upvotes: 0
Reputation: 91326
How about:
filesystem.CopyFile "d:\x\logs\" & file.name, "d:\completed logs\"
Upvotes: 3