Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Listing

Status
Not open for further replies.

HRTECH

MIS
Feb 10, 2004
48
US
Ok this is going to seem like a stupid question, however I cannot seem to find it.

I need to get a listing of all files modified before 3/16/02 so I can put them on CD and remove them from the computer for archival purposes. I know I can do it using find files however I want to be able to print a report so I can get approval from the Directors to remove the files. I have tried looking at the old dos command dir and piping it to a file however I can't find a way to list just the files modified before then.

Any help is greatly appreciated.

Thanks,
Harold
 
This should do it for you. Just change the "path"
When prompted for File Age tell it how many days old the file should be. It uses the last modified date.



'==========================================================================
'
' NAME: ReportFilesbyAge.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: ' DATE : 3/16/2004
'
'==========================================================================

Dim fso
Dim oFolder
Dim oFile

Set fso = createobject("Scripting.FileSystemObject")

FileAge = InputBox("How old should the file be?","File Age?")
Action = InputBox("Report or Delete Files?" & vbCRLF & "Answer REPORT or DELETE","Action to take?")
Report = ""
Path = "C:\Temp"

Set oFolder = fso.GetFolder(Path)

FileAction(Action)


Set oFolder = Nothing
Set fso = Nothing
MsgBox "done"

Function FileAction(Action)

For Each oFile In oFolder.files
If DateDiff("d", oFile.DatelastModified,Now) > Int(FileAge) Then

If ucase(Action) = "DELETE" Then
oFile.Delete True
Else
'MsgBox Action
Report = Report & oFile.name & " Created on " & oFile.DateCreated & " last modified "& oFile.DatelastModified & vbCrLf
End If
End If
Next

If ucase(Action) = "REPORT" Then
Set ts = fso.CreateTextFile ("C:\FilesAge.txt", ForWriting)
ts.write report
End If

End Function


I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Also, although this probably goes without saying, remember to NOT remove files from the following Directory Structures:

C:\Windows
C:\WinNT
C:\i386

Seumas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top