Lico_w
asked on
VBScript To Find Modified Files in ALL directories
I would like to scan my server for files which have been recently modified i.e. in the last hour. The OS is Win 2K, and the best way to do this from what I can see is through a VBScript. I have created the below but this only searches a single directory, how can I modify it to search sub directories?
Const srcDir = "C:\Docume~1\SearchDirecto ry"
Const destDir = "C:\Docume~1\filesModified "
hourAgo = DateAdd("h", -1, Now)
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
For Each f In fso.GetFolder(srcDir).File s
If f.DateLastModified > hourAgo Then _
f.Copy destDir & "\"
Next 'f
Const srcDir = "C:\Docume~1\SearchDirecto
Const destDir = "C:\Docume~1\filesModified
hourAgo = DateAdd("h", -1, Now)
Set fso = CreateObject("Scripting.Fi
For Each f In fso.GetFolder(srcDir).File
If f.DateLastModified > hourAgo Then _
f.Copy destDir & "\"
Next 'f
Here's the basic idea, didn't test it but hope it's close.
~bp
~bp
Const srcDir = "C:\Docume~1\SearchDirectory"
Const destDir = "C:\Docume~1\filesModified"
hourAgo = DateAdd("h", -1, Now)
Set fso = CreateObject("Scripting.FileSystemObject")
ScanFolder(srcDir)
Function ScanFolder(strFolder)
For Each f In fso.GetFolder(srcDir).Files
If f.DateLastModified > hourAgo Then f.Copy destDir & "\"
Next
For Each sf in fso.GetFolder(srcDir).SubFolders
ScanFolder(sf.Path)
Next
End Function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi guys, slightly confused I'm afraid. ged325 I can't get yours to work I've tried a few things but don't fully understand what I need to do to get this working.
billprew I also tried your method but when ran I get a Microsoft runtime error saying out of memory fso.getFolder.
Please help...
billprew I also tried your method but when ran I get a Microsoft runtime error saying out of memory fso.getFolder.
Please help...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I re-looked at this and managed to get it working from ged325's post (33596512), although I have also just tested the post from billprew and it too works perfectly.
So I'll award you both points.
So I'll award you both points.
ASKER
Both solutions worked equally well, many thanks!!!!
Great, glad that was useful. Thanks.
~bp
~bp
Function ShowFolderList(folderspec)
Dim fso, f, f1, s, sf
Set fso = CreateObject("Scripting.Fi
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
you'll want to recurse on the for each f1 . . . call you function to do your search again.