[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script needed to report on old files

Posted on 2008-06-11
5
Medium Priority
?
218 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 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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 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