tags:

views:

103

answers:

4

Hi, 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.

+1  A: 

How about:

filesystem.CopyFile "d:\x\logs\" & file.name, "d:\completed logs\"
Remou
brilliant, thanks a lot for your help. I can see where I was going wrong now.
Martin North
A: 

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

Chris Farmer
+1  A: 

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

Jibba
A: 

Thanks for the replies. I was using an * to try and catch files where I didn't know the full name (the file name has the day appeneded to it each day, e.g file01 file02 etc)

I guess now I just need to read in the date and use an if statement to find if the filename contains the day. Or is there a better way?

many thanks

Martin.

Martin North
When you go through the files in the directory, file.name holds the name of a file with a modification date of "today", it can the be copied. Did you want to check something else as well?
Remou
BTW, you should edit your initial question, rather than posting an "answer" :)
Remou