开发者

VBScript - copy files modified in last 24 hours

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:\complet开发者_开发百科ed 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.


How about:

filesystem.CopyFile "d:\x\logs\" & file.name, "d:\completed logs\"


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


It looks like you are copying all files if any file satisfies the DateDiff comparison.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜