Link to home
Create AccountLog in
Avatar of Damarado
Damarado

asked on

Script to clean up folders and sub folders on file server

Hi

I am looking for a script that will run on a scheduled weekly task and deletes any content in the folders older then one week.

Our file server is running windows 2012.

There are users with root and sub folders as shown

     user                            jreeds
     subfolders                 jreeds-a1
                                         jreeds-a2
                                         jreeds-a3
                                        jreeds-a4
                                        jreeds-a5

I only want the content scrubbed from the sub folders for each user, not the root folder for the user
Any files older than a week will be deleted, otherwise left alone.

any new folders in the sub folders will not be touched.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of nashiooka
nashiooka

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Bill Prew
Bill Prew

So, does it look something like this then?

x:\basedir\jreeds\jreeds-a1\sub1
x:\basedir\jreeds\jreeds-a1\sub2
x:\basedir\jreeds\jreeds-a2
x:\basedir\jreeds\jreeds-a3
x:\basedir\jreeds\jreeds-a4\sub3
x:\basedir\jreeds\jreeds-a5

And you only want to remove old files from:

x:\basedir\jreeds\jreeds-a1
x:\basedir\jreeds\jreeds-a2
x:\basedir\jreeds\jreeds-a3
x:\basedir\jreeds\jreeds-a4
x:\basedir\jreeds\jreeds-a5

And not:

x:\basedir\jreeds\
x:\basedir\jreeds\jreeds-a1\sub1
x:\basedir\jreeds\jreeds-a1\sub2
x:\basedir\jreeds\jreeds-a4\sub3

If so, are the a1 through a4 always constant and the same and should be hard coded, or could they be any name that lives at the first level of the user folder?

~bp