Solved

Script needed to report on old files

Posted on 2008-06-11
5
203 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now