Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Find the oldest file in a folder

Status
Not open for further replies.

gali1

IS-IT--Management
Jul 17, 2008
1
US
I am a new at VBScripting and need some help...I am trying to create a script that will monitor a folder for any file older than 1 hour, this is what I have so far:

'Desc :Check files age
' Return age of files in the folder, -1 if it encounter error.
'USAGE :FNChkFileAge [path] [file]
'

Dim Fname,oShell, FSO

path = Wscript.Arguments(0)
file = Wscript.Arguments(1)


' Create a FileSystemObject and use it to check
' if the file exists
'

Set FSO= CreateObject("Scripting.FileSystemObject")
set Fname = FSO.GetFile(path & "\" & file)

wscript.echo Fname & " created on: " & Fname.DateCreated
wscript.echo Fname & " last updated: " & Fname.DateLastModified

wscript.echo "Current datetime: " & now()
wscript.echo "Current date: " & date

dFileModDate = Fname.DateLastModified

FileAge = DateDiff("h", dFileModDate, Now)
wscript.echo "FileAge: " & FileAge
If DateDiff("h", dFileModDate, Now) > 1 Then
wscript.echo "Warning: File idled for more than 1 hour!"
End If

'FileAge = now() - Fname.DateCreated
'wscript.echo FileAge
'wscript.echo "yr " & year(fileage)
'wscript.echo "hour " & hour(fileage)
'wscript.echo "mm " & minute(fileage)

wscript.quit


Any help is apriciated. TIA.
 
Use the Files collection of the Folder object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top