Link to home
Start Free TrialLog in
Avatar of rcoast
rcoast

asked on

Script to delete files after X days

I need a script that will recursively delete all files, based upon a pattern, that are older than X days, from a starting directory.

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of William Elliott
William Elliott
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rcoast
rcoast

ASKER

Thank you!

I would like to do a pattern match on the files (such as *.bak). Can that be added easily?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rob: well aren't you mister fancy pants  :)
Actually, looking at that, the recursion bit is commented out.  Change this bit near the bottom:
  Next
  'If UCase(RecurseOn) = "YES" Then
        recurse subfolder, strPartOfFileName
  'End If
  Next

to this
  Next
  If UCase(RecurseOn) = "YES" Then
        recurse subfolder, strPartOfFileName
  End If
  Next

so that the recursion flag works.

You will also need to uncomment all of the
file.delete
lines when you actually want to delete them.

I guess I should have added an "output only" flag as well.....

Regards,

Rob.
@ Weelio,
LOL!  Thanks, but not really....I just adapted it from another "delete files older than" script, and as I said, I haven't tested it that much.....hopefully it works....give it a whirl.....

P.S. I don't like fancy pants that much either.....I'm not much of a "colourful" guy.....I tend to play it *safe* in the fasion sense......although sometime my wife says differently..... :-)

Regards,

Rob.
Avatar of rcoast

ASKER

Thank you!