![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Clean out old files from multiple subfolders Hey everyone. Does anyone have or would be able to write a script that would go through a big folder structure, and only when it finds certain subfolders, delete files of a certain age out of those specific subfolders? I have a Users share, then a subfolder for each user, then a few levels under that there are a couple folders with unique names, lets call them Folder1 and Folder2, that I need to clear out of any files older than a month from the current date when I run the script. If I don't have to do this manually for a few hundred people, I might actually see sunlight again haha. Thanks in advance!! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Clean out old files from multiple subfolders "Rich" <richjone@xxxxxx> wrote in message news D70792B-327A-4572-B542-4EB18B80CCE3@xxxxxxQuote: > Hey everyone. Does anyone have or would be able to write a script that > would > go through a big folder structure, and only when it finds certain > subfolders, > delete files of a certain age out of those specific subfolders? > > I have a Users share, then a subfolder for each user, then a few levels > under that there are a couple folders with unique names, lets call them > Folder1 and Folder2, that I need to clear out of any files older than a > month > from the current date when I run the script. > > If I don't have to do this manually for a few hundred people, I might > actually see sunlight again haha. Thanks in advance!! http://groups.google.co.kr/group/mic...9d6f3276436245. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Clean out old files from multiple subfolders 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. "Pegasus [MVP]" wrote: Quote: > > "Rich" <richjone@xxxxxx> wrote in message > news D70792B-327A-4572-B542-4EB18B80CCE3@xxxxxxQuote: > > Hey everyone. Does anyone have or would be able to write a script that > > would > > go through a big folder structure, and only when it finds certain > > subfolders, > > delete files of a certain age out of those specific subfolders? > > > > I have a Users share, then a subfolder for each user, then a few levels > > under that there are a couple folders with unique names, lets call them > > Folder1 and Folder2, that I need to clear out of any files older than a > > month > > from the current date when I run the script. > > > > If I don't have to do this manually for a few hundred people, I might > > actually see sunlight again haha. Thanks in advance!! > Have a look here: > http://groups.google.co.kr/group/mic...9d6f3276436245. > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Clean out old files from multiple subfolders "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. > 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 |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Clean out old files from multiple subfolders Rich wrote: Quote: > Wow, I think that is like 90% what I'm looking for. Looks like that Quote: > deletes the files out of all subfolders. I only need to have it delete Quote: > of MaxAge out of specifically named subfolders, like Folder1 and Folder2 Quote: > 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 Quote: > 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 Interestingly enough, it has provision for what you want. You just set the constant "Recursive " to FALSE, then it will not look for files in subfolders. Quote: > > "Pegasus [MVP]" wrote: > Quote: > > > > "Rich" <richjone@xxxxxx> wrote in message > > news D70792B-327A-4572-B542-4EB18B80CCE3@xxxxxxQuote: > > > Hey everyone. Does anyone have or would be able to write a script Quote: Quote: Quote: > > > would > > > go through a big folder structure, and only when it finds certain > > > subfolders, > > > delete files of a certain age out of those specific subfolders? > > > > > > I have a Users share, then a subfolder for each user, then a few Quote: Quote: Quote: > > > under that there are a couple folders with unique names, lets call Quote: Quote: Quote: > > > Folder1 and Folder2, that I need to clear out of any files older than Quote: Quote: Quote: > > > month > > > from the current date when I run the script. > > > > > > If I don't have to do this manually for a few hundred people, I might > > > actually see sunlight again haha. Thanks in advance!! > > Have a look here: > > Quote: Quote: > > > > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Clean out old files from multiple subfolders Pegasus [MVP] wrote: Quote: > Rich wrote: 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, Quote: Quote: > > 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 Quote: > current folder. Lines [24]/[33] in the script below will do this. Line Quote: > contains a list of folder names that are subject to deletion. Each name Quote: > 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 (or remove lines 35 thru 38) -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Clean out old files from multiple subfolders "Todd Vargo" <tlvargo@xxxxxx> wrote in message news:uclsIY86JHA.1424@xxxxxx Quote: > Pegasus [MVP] wrote: Quote: >> Rich wrote: 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, Quote: Quote: >> > 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 Quote: >> current folder. Lines [24]/[33] in the script below will do this. Line Quote: >> contains a list of folder names that are subject to deletion. Each name Quote: >> 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 > And remember to set "Recursive" on line [10] to False. > (or remove lines 35 thru 38) > > -- > Todd Vargo > (Post questions to group only. Remove "z" to email personal messages) > inside his folder structure then "Recursive" should be set to True. |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Clean out old files from multiple subfolders Thanks Pegasus, I will give this a shot. If I have any issues I will let you know via a reply posting. "Pegasus [MVP]" wrote: Quote: > > "Todd Vargo" <tlvargo@xxxxxx> wrote in message > news:uclsIY86JHA.1424@xxxxxx Quote: > > Pegasus [MVP] wrote: Quote: > >> Rich wrote: > >> > 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, Quote: > >> > 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 Quote: > >> current folder. Lines [24]/[33] in the script below will do this. Line Quote: > >> contains a list of folder names that are subject to deletion. Each name Quote: > >> 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 > > And remember to set "Recursive" on line [10] to False. > > (or remove lines 35 thru 38) > > > > -- > > Todd Vargo > > (Post questions to group only. Remove "z" to email personal messages) > > > Hhm, well, not quite. Since the OP says that the named folder is buried deep > inside his folder structure then "Recursive" should be set to True. > > > |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Clean out old files from multiple subfolders Pegasus, The script works like a champ. and it also pointed out a flaw in my description haha. In my Folder2, the files I actually want to clean out are within randomly named subfolders of Folder2. The files i want to delete out of everyone's Folder1 are exactly inside Folder1, no subfolders whatsoever so that part works flawlessly. "Rich" wrote: 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. > > "Pegasus [MVP]" wrote: > Quote: > > > > "Rich" <richjone@xxxxxx> wrote in message > > news D70792B-327A-4572-B542-4EB18B80CCE3@xxxxxxQuote: > > > Hey everyone. Does anyone have or would be able to write a script that > > > would > > > go through a big folder structure, and only when it finds certain > > > subfolders, > > > delete files of a certain age out of those specific subfolders? > > > > > > I have a Users share, then a subfolder for each user, then a few levels > > > under that there are a couple folders with unique names, lets call them > > > Folder1 and Folder2, that I need to clear out of any files older than a > > > month > > > from the current date when I run the script. > > > > > > If I don't have to do this manually for a few hundred people, I might > > > actually see sunlight again haha. Thanks in advance!! > > Have a look here: > > http://groups.google.co.kr/group/mic...9d6f3276436245. > > > > > > |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Clean out old files from multiple subfolders "Rich" <richjone@xxxxxx> wrote in message news AB64110-544F-4DDA-B18E-F0DC5323B5C3@xxxxxxQuote: > Pegasus, > > The script works like a champ. and it also pointed out a flaw in my > description haha. In my Folder2, the files I actually want to clean out > are > within randomly named subfolders of Folder2. The files i want to delete > out > of everyone's Folder1 are exactly inside Folder1, no subfolders whatsoever > so > that part works flawlessly. > > "Rich" wrote: > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Unzip a zip file which contains multiple subfolders using VBSCRIPT?! | VB Script | |||
| Batch file to execute files in subfolders | PowerShell | |||
| List files in folder with subfolders at top? | Vista file management | |||
| creating a new folder in multiple subfolders | Vista General | |||
| Application subfolders in Program Files | Vista security | |||