?
Solved

Script needed to report on old files

Posted on 2008-06-11
5
Medium Priority
?
216 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:gdPAC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 21764380
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

0
 

Author Comment

by:gdPAC
ID: 21769334
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.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 21776430
Try this script.

Regards,

Rob.
strFolder = "C:\TEMP\Temp\Test script\Test\Documents"
strOutputFile = "OldFileLog.txt"
intDaysOld = 30
Set objFSO = CreateObject("Scripting.FileSystemObject")
strResults = "FILES OLDER THAN " & intDaysOld & " DAYS"
RecurseFolder strFolder, intDaysOld
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing
MsgBox "Done"
 
Sub RecurseFolder(strPath, intAge)
	If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
	If Right(LCase(strPath), 12) = LCase("Local Store\") Then
		For Each objFile In objFSO.GetFolder(strPath).Files
			If DateDiff("d", objFile.DateLastModified, Now) > intAge Then
				strResults = strResults & VbCrLf & objFile.Path & "   " & objFile.DateLastModified
			End If
		Next
	End If
	For Each objSubFolder In objFSO.GetFolder(strPath).SubFolders
		RecurseFolder objSubFolder.Path, intAge
	Next
End Sub

Open in new window

0
 

Author Closing Comment

by:gdPAC
ID: 31472320
Works GREAT!  Thanks for the help.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21912456
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question