Solved

Script needed to report on old files

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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