VBS for moving files with today's Date

October 15, 2012 at 08:11:43
Specs: XP\7
So far I have a script that is showing me the last modified file in a particular path. I now want to say if files with today's date exist move them to another folder, and if not popup a message box that says no Updates. This is what I have so far.

Set objFSO = CreateObject("Scripting.FileSystemObject")

FolderToScan = "c:\"

Set objFolder = objFSO.GetFolder(FolderToScan)

NewestFile = ""
NewestDate = Date

For Each objFile In objFolder.Files
If objFile.DateLastModified > NewestDate Then
NewestDate = objFile.DateLastModified
NewestFile = objFile.Name
End If
Next

WScript.Echo NewestFile


See More: VBS for moving files with todays Date

Report •


#1
October 15, 2012 at 18:20:02
flag="no updates"
For Each objFile In objFolder.Files
If datediff("d",objFile.DateLastModified,date)=0 Then
objfso.movefile(foldertoscan&"\"&objfile.name,destdir)
flag=""
End If
Next
wscript.echo (flag)
'======== end vbscript

Rough draft, not sure about fso.copyfile if the file needs ".name".


Report •

#2
October 15, 2012 at 21:14:18
nbrane: Rough draft, not sure about fso.copyfile if the file needs ".name".
It's always nice to see someone else pick up the now depreciated language that is VBScript. Two small critiques, though.
1) The File object does have a Move method.
2) The default property of File objects is Path, so whenever you have a file object and a method requires a string, feel free to feed in a File object. As an aside, this is why you must Set objects to variables; to differentiate between the object itself and its default property.

How To Ask Questions The Smart Way


Report •

Related Solutions


Ask Question