Discussion:
Files in a folder based on a date filter
(too old to reply)
d***@gmail.com
2016-02-03 14:30:51 UTC
Permalink
Hi,

I'm using a bunch of scripts that scan through a folder looking for new files. Every day the folder has more files and it starting to take a lot of time. Is there a way to somehow speed up the process by using a date parameter when opening the folder with the GetFolder?

I fear there isn't one, do you have any suggestions on how to speed up things when searching for new files in a long list of files?
Mayayana
2016-02-03 14:49:53 UTC
Permalink
Here's what I have. I don't know if it's any
faster than what you have, since you didn't
post that.
I don't think there's anything to make Windows
do it. Even if there were, it might not be more
efficient.

You drop a folder onto this script, enter a date,
and it generates a list:

Dim FSO, arg, sPath, sDate, s, TS
On Error Resume Next

If WScript.Arguments.count > 0 Then
sPath = WScript.Arguments.item(0)
Else
sPath = InputBox("Enter Path of folder", "Find Changed Files")
End If
If sPath = "" Then WScript.Quit

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(sPath) = False Then
MsgBox "Not a valid folder path.", 64
Set FSO = Nothing
WScript.Quit
End If

sDate = InputBox("Enter date to check as 8/4/02, 12/21/01, etc", "Find
Changed Files")

If sDate = "" Then
Set FSO = Nothing
WScript.Quit
End If

If isdate(sDate) = False Then
MsgBox "Not a valid date.", 64
Set FSO = Nothing
WScript.Quit
End If

s = CheckDates(sPath, sDate)
If s <> "" Then
Set TS = FSO.CreateTextFile("C:\DateChanges.txt", True)
TS.Write s
TS.close
Set TS = Nothing
MsgBox "Files modified since " & sDate & "are listed in C:\DateChanges.txt
file."
Else
MsgBox "No files modified since " & sDate
End If
Set FSO = Nothing

'//////////////////////////////////////////////////////////////////////
'--this Function runs recursively through the folder and subfolders
'--of the path provided as FolPath. It uses DateDiff to compare the
'--number of days between today and the date provided to the script.
'-- That number is held in iDays.
'-- It Then checks all files and adds them to the list If any have
'-- a (Today - DateLastModified) number less than iDays.
'-- This can work because Each instance of the Function is a separate
'-- operation that just happens to be called from within the Function.
'-- That is, the variables Fol, SubPath, etc. are separate variables in
'-- Each instance of the Function.
Function CheckDates(FolPath, FilDate)
Dim oFol, Fols, Fils, oFol1, oFil, sD1, iDays, sList, SubPath, s1
iDays = DateDiff("d", FilDate, now)

Set oFol = FSO.GetFolder(FolPath)
'--Get files in folder and compare their date to today:
Set Fils = oFol.Files
If Fils.count > 0 Then
For Each oFil in Fils
sD1 = oFil.DateLastModified
If DateDiff("d", sD1, now) < iDays Then
sList = sList & oFil.Path & " -- " & sD1 & vbCrLf
End If
Next
End If
'--Run the same routine For subfolders:
Set Fols = oFol.SubFolders
If Fols.count > 0 Then
For Each oFol1 in Fols
SubPath = oFol1.Path
s1 = CheckDates(SubPath, FilDate)
sList = sList & s1
Next
End If
Set Fols = Nothing
Set Fils = Nothing
Set oFol = Nothing
CheckDates = sList
End Function

Loading...