Solved

Script needed to report on old files

Posted on 2008-06-11
5
212 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
  • 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 125 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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