Find most recently modified file
Hi Guys,
I'm looking for a way to find the most recently modified file in a directory using vbscript. Basically I need to find the most recent backup log in a directory and I have found that you can use DateDiff to compare two dates so at the moment im just checking each file in the directory to see if it is less than a day since it has last been modified but then obviously this does not work on a monday...because the backup finishes writing to the log file on Friday so when the script comes to run on Monday there is nothing thats been modified within the last 24 hrs.
Cheers
Chris
Re: Find most recently modified file
vb Code:
Set oFS = CreateObject("Scripting.FileSystemObject")
Set ofp = ofs.GetFolder("C:\Documents and Settings\peter\My Documents\basic\vbs")
Set ofiles = ofp.Files
For Each fi In ofiles
If newest = "" Then newest = fi.Name: Set newfile = fi
If fi.DateLastModified > newfile.DateLastModified Then
Set newfile = fi
newest = fi.Name
End If
Next
msgbox newest