vbscript DateLastModified

A

Anonymous

The following script is a small piece of a larger script. I am trying to
move all text files that begin with "BA" and are older than today to a
different folder. The script does not give me any erros. The issue is that
is still moves all the files that begin with "BA" regardless of the date
modified.

3 files named:

BA20090815.txt
BA20090816.txt
BA20090817.txt

Only files BA20090815.txt and BA20090816.txt should be moved but all 3 files
are being moved.

If I put in the code wsh.echo objFile.DateLastModified the correct 2 files
appear. Here is the code:

Set fso = CreateObject("Scripting.FileSystemObject")
Set objfolder = fso.getfolder("c:\document\BLMed")
For Each objFile in objFolder.Files
If Left(objFile.Name, 2) = "BA" Then
If DateDiff("d", objFile.DateLastModified, Now) > 1 Then
fso.MoveFile "c:\document\BLMed\BA*.txt", "c:\document\BLMed\Logs\"
'wsh.echo objFile.DateLastModified
End If
End If
Next

I do not want to use a bat or cmd file or robocopy because this is a small
piece of a bigger script. The rest of the script works except this one piece.

Thanks!
 
A

Anonymous

Thanks for the link. I looked for a scripting forum but didn't see this one
so didn't know it existed. Thanks again.
 
A

Anonymous

That did the trick. Thanks!

Pegasus said:
How nice of Anon to do the crossposting for you! Instead of writing
fso.MoveFile "c:\document\BLMed\BA*.txt" . . .

you must write

fso.MoveFile objFile.path . . .

If you don't then you will move all files, thanks to the wildcard you left
in your code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top