Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Clean out old files from multiple subfolders

Reply
 
Old 06-12-2009   #1 (permalink)
Rich


 
 

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 SpecsSystem Spec
Old 06-12-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Clean out old files from multiple subfolders


"Rich" <richjone@xxxxxx> wrote in message
newsD70792B-327A-4572-B542-4EB18B80CCE3@xxxxxx
Quote:

> 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 SpecsSystem Spec
Old 06-12-2009   #3 (permalink)
Rich


 
 

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
> newsD70792B-327A-4572-B542-4EB18B80CCE3@xxxxxx
Quote:

> > 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 SpecsSystem Spec
Old 06-12-2009   #4 (permalink)
Pegasus [MVP]


 
 

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.
>
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


My System SpecsSystem Spec
Old 06-12-2009   #5 (permalink)
Todd Vargo


 
 

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
script
Quote:

> deletes the files out of all subfolders. I only need to have it delete
files
Quote:

> of MaxAge out of specifically named subfolders, like Folder1 and Folder2
in
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
folders
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
bad.

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
> > newsD70792B-327A-4572-B542-4EB18B80CCE3@xxxxxx
Quote:

> > > Hey everyone. Does anyone have or would be able to write a script
that
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
levels
Quote:
Quote:
Quote:

> > > under that there are a couple folders with unique names, lets call
them
Quote:
Quote:
Quote:

> > > Folder1 and Folder2, that I need to clear out of any files older than
a
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:
> >
http://groups.google.co.kr/group/mic...9d6f3276436245.
Quote:
Quote:

> >
> >
> >
My System SpecsSystem Spec
Old 06-12-2009   #6 (permalink)
Todd Vargo


 
 

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,
which
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
the
Quote:

> current folder. Lines [24]/[33] in the script below will do this. Line
[08]
Quote:

> contains a list of folder names that are subject to deletion. Each name
must
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)

My System SpecsSystem Spec
Old 06-13-2009   #7 (permalink)
Pegasus [MVP]


 
 

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,
> which
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
> the
Quote:

>> current folder. Lines [24]/[33] in the script below will do this. Line
> [08]
Quote:

>> contains a list of folder names that are subject to deletion. Each name
> must
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 SpecsSystem Spec
Old 06-15-2009   #8 (permalink)
Rich


 
 

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,
> > which
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
> > the
Quote:

> >> current folder. Lines [24]/[33] in the script below will do this. Line
> > [08]
Quote:

> >> contains a list of folder names that are subject to deletion. Each name
> > must
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 SpecsSystem Spec
Old 06-16-2009   #9 (permalink)
Rich


 
 

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
> > newsD70792B-327A-4572-B542-4EB18B80CCE3@xxxxxx
Quote:

> > > 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 SpecsSystem Spec
Old 06-16-2009   #10 (permalink)
Pegasus [MVP]


 
 

Re: Clean out old files from multiple subfolders


"Rich" <richjone@xxxxxx> wrote in message
newsAB64110-544F-4DDA-B18E-F0DC5323B5C3@xxxxxx
Quote:

> 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:
>
Thanks for the feedback.


My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46