VBScript - Find the oldest file in a folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • galilea
    New Member
    • Jul 2008
    • 1

    VBScript - Find the oldest file in a folder

    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.Argumen ts(0)
    file = Wscript.Argumen ts(1)


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

    Set FSO= CreateObject("S cripting.FileSy stemObject")
    set Fname = FSO.GetFile(pat h & "\" & file)

    wscript.echo Fname & " created on: " & Fname.DateCreat ed
    wscript.echo Fname & " last updated: " & Fname.DateLastM odified

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

    dFileModDate = Fname.DateLastM odified

    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.DateCreat ed
    'wscript.echo FileAge
    'wscript.echo "yr " & year(fileage)
    'wscript.echo "hour " & hour(fileage)
    'wscript.echo "mm " & minute(fileage)

    wscript.quit
Working...