Link to home
Start Free TrialLog in
Avatar of MCPJoe
MCPJoeFlag for United States of America

asked on

Script help - deleting files older than certain number of days

I have various sets of folders in a particular folder structure on a windows machine, that I have my backups going to.  My backup runs a backup to disk job that dumps the B2D files in various folders for various servers.  What I need to do is retain 3 days worth of these B2D files, and get rid of the rest.  Every night I run a backup of the B2D Files to tape, so deleting them is ok.  Can someone help me put together a VB script (or whatever method is best) to delete .bkf files with a data modified of older than 3 days.  I just want to keep 3 days worth of files, so anything older than 3 days can be deleted.  Any help would be greatly appreciated.

Thanks
Avatar of aplimedia
aplimedia
Flag of Spain image

Best move this this question to Visual basics... you are not going to get much help here in Javascript


Aplimedia
SOLUTION
Avatar of schworak
schworak

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 MCPJoe

ASKER

So if I only wanted it to dele files older than 3 days, I would change the 7 in your code to a 3, and add the debug.print in the end of your message to replace the existing debug.print line.  And that should do it right?
ASKER CERTIFIED 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
SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
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 schworak
schworak

All variations on the same theme. Each would work depending on the particulars of your delete needs.

I use this concept in a backup process of my own with a little more complexity. I backup each day to a different folder based on the date (backup_061103 for example) and I keep 7 backup folders regardless of how old they are and delete the oldest ones first.

I do this just in case a backup fails to run one day I still have 7 backup folders. (which actually happens once in a while) I learned this after going by date and my backup kept failing and one day I realized I had NO BACKUPS at all because all folders were over 7 days old. Good thing nothing got lost while I was on vacation.

I used the DIM ... AS OBJECT so I wouldn't have to reference the scripting object but if you do reference it you get some nice features while in the editor. Functionally, it makes no difference.
Avatar of MCPJoe

ASKER

Thanks for the input.  I am going to try a few of these and see which one works best for my needs.  Its really simple, I just need something to start at a root level folder, delete any .bkf file with a modified date older than 3 days.  One tricky part I just thought of would be the weekend.  We are about to start a 7 day a week rotation, but currently are only doing 5.  So how would I handle the weekend, because the on Sunday night the modified date would delete some valid backups I want to keep.  Is there a way in this script that would allow for the weekend too and not delete Wednesday's backup until Monday?