| Welcome to Lieben Knowledgebase! |

At some point I needed a VBScript to check a certain folder/directory for 'recent' files. In other words, I wanted to know if my backup had been created, and if the corresponding 2 new files with undetermined filenames were there.
So, here is a script which checks a folder for files made the same day the script is run. Of course this can be easily altered to check for several days, or hours, etc. The script will return a ERRORLEVEL=1 (nice for batch scripting) if there are not at least 2 new files, otherwise it will exit cleanly.
Option Explicit
CONST PATH = "c:\backup"
dim strNow
dim strShare
dim fso
dim objFolder
dim colFiles
dim objFile
dim strFile
dim count
Set fso = CreateObject("Scripting.FileSystemObject")
strNow = Now()
Set objFolder = fso.GetFolder(PATH)
Set colFiles = objFolder.Files
count=0
For Each strFile in colFiles
Set objFile = fso.GetFile(strFile)
If DateDiff("d", objFile.DateLastModified, strNow) = 0 Then
count=count+1
End If
Set objFile = Nothing
Next
If count < 2 Then
Wscript.Quit(1)
End If
Wscript.Quit
added by Jos on: 29-01-2010
keywords: VBScript, File dates, backup,