Link to home
Start Free TrialLog in
Avatar of gdPAC
gdPACFlag for United States of America

asked on

Script needed to report on old files

I need a script or freeware utility that will report on all files older than "n" days in a Windows 2000 directory tree with the following structure:

documents
 +user
   +my documents
     +user's local store

I want to scan all folders under "documents" matching "*local store\" and list all files in those folders that are older than a specified date with relative paths back to "user's local store\" along with the modified date to a text file.  I've gotten close with FORFILES but it includes ALL subfolders in the tree instead of just the "local store" folders.

Example output:
FILES OLDER THAN 30 DAYS
Glen's Local Store\HAL9000.src 10/10/2007
Harold's Local Store\Secrets of the Universe.csv 3/27/1962
Harold's Local Store\LOTR.wav 2/2/2008

Thanks!
Glen
Avatar of RobSampson
RobSampson
Flag of Australia image

What if you just use FORFILES to output to a file, then have a VBS run through that file and quickly remove any line that doesn't have
Local Store\

in it?

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
strForFilesLog = "ForFilesLog.txt"
Set objFile = objFSO.OpenTextFile(strForFilesLog, intForReading, False)
strContents = ""
While Not objFile.AtEndOfStream
	strLine = objFile.ReadLine
	If InStr(LCase(strLine), LCase("Local Store\")) > 0 Then
		If strContents = "" Then
			strContents = strLine
		Else
			strContents = strContents & VbCrLf & strLine
		End If
	End If
Wend
objFile.Close
Set objFile = Nothing
Set objFile = objFSO.CreateTextFile(strForFilesLog, True)
objFile.Write strContents
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
MsgBox "Done"

Open in new window

Avatar of gdPAC

ASKER

That works, but it doesn't scale well.  I didn't run a timer, but it took well over 20 minutes to generate a report.  It would be much more efficient to crawl a tree looking for a specified string ("local store" in this case) in the path name and then add lines to a text file of the relative path\file names that meet the age criteria.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gdPAC

ASKER

Works GREAT!  Thanks for the help.
No problem. Thanks for the grade.

Regards,

Rob.