Detect files changed since "n" daysTag(s): WSH VBScript


[filechange.vbs]

Function FilesModifiedSince (FolderSpec, Days)
  Dim fso, fc, f, d
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set fc = fso.GetFolder(FolderSpec).Files
  Set d = CreateObject("Scripting.Dictionary")

  For Each f in fc
    If DateDiff("d", f.DateLastModified, Now) <= Days Then d.Add f, f.DateLastModified
  Next
  Set fso = Nothing
  Set fc = Nothing
  Set FilesModifiedSince = d
End function

' Example, get all the files modifed since 5 days
' in the specified directory
Dim a, f

Set f  = FilesModifiedSince("c:\dev\work\scripting", 5)
a = f.keys
b = f.items

For i = 0 To f.count - 1
  WScript.Echo  a(i) & "   " & b(i)
Next

Set f = Nothing
WScript.Quit(0)

blog comments powered by Disqus