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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Old Files 2

Status
Not open for further replies.

mar74

IS-IT--Management
Aug 12, 2003
22
0
0
US
I'm trying to write a script that will sweep through and delete files older than 3 months. The script works fine on the folder I specify but I need to sweep through all of the subfolders as well. Any help is much appreciated. Here is the script:

Option Explicit
on error resume next
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld


iDaysOld = 90
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "C:\Archive"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFileCollection = oFolder.Files

For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
oFile.Delete(True)
End If
Next

Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
 
make a collection of folders first, then for each subfolder in folders put your files collection

_______
I love small animals, especially with a good brown gravy....
 
Or simpler, write a recursive function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top