|
-
Sep 21st, 2007, 08:34 AM
#1
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
-
Sep 22nd, 2007, 08:09 AM
#2
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|