"Rich" <richjone@xxxxxx> wrote in message
news:EFC9755C-E36C-4B6B-A338-D2CB40604276@xxxxxx
Quote:
> Wow, I think that is like 90% what I'm looking for. Looks like that
> script
> deletes the files out of all subfolders. I only need to have it delete
> files
> of MaxAge out of specifically named subfolders, like Folder1 and Folder2
> in
> my example. How could I make it do that?
>
> For instance, under Users, say i have folders named Users000 through
> Users100. Then under each Users### folder there are 12 subfolders, which
> have subfolders, and buried somewhere in that subfolder mess are two
> folders
> named Folder1 and Folder2. I only want to delete files of MaxAge within
> Folder1 and Folder2. Deleting them from any other folder would be VERY
> bad.
>
You need to make the file deletion process conditional upon the name of the
current folder. Lines [24]/[33] in the script below will do this. Line [08]
contains a list of folder names that are subject to deletion. Each name must
be delimited on both sides with a vertical bar.
[01] '--------------------------------------------
[02] 'This script will delete files that were last
[03] 'updated "MaxAge" or more days ago.
[04] '13.6. FNL
[05] '--------------------------------------------
[06] Const Active = False
[07] Const sSource = "d:\Users"
[08] Const sFolderNames = "|folder1|folder2|folderx|" 'Lower case!
[09] Const MaxAge = 10 'days
[10] Const Recursive = True
[11]
[12] Checked = 0
[13] Deleted = 0
[14]
[15] Set oFSO = CreateObject("Scripting.FileSystemObject")
[16] if active then verb = "Deleting """ Else verb = "Old file: """
[17] CheckFolder oFSO.GetFolder(sSource)
[18]
[19] WScript.echo
[20] if Active then verb = " file(s) deleted" Else verb = " file(s) would be
deleted"
[21] WScript.Echo Checked & " file(s) checked, " & Deleted & verb
[22]
[23] Sub CheckFolder (oFldr)
[24] If InStr(sFolderNames, "|" & LCase(oFldr.Name) & "|") > 0 Then
[25] For Each oFile In oFldr.Files
[26] Checked = Checked + 1
[27] If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
[28] Deleted = Deleted + 1
[29] WScript.Echo verb & oFile.Path & """"
[30] If Active Then oFile.Delete
[31] End If
[32] Next
[33] End If
[34]
[35] if not Recursive then Exit Sub
[36] For Each oSubfolder In oFldr.Subfolders
[37] CheckFolder(oSubfolder)
[38] Next
[39] End Sub