Delete files older than _X_ days

Post your handy scripts here, or any requests for help in creating a script.
Forum rules
1. Try to give more than you take, when possible.
2. Always wrap code in
Code: Select all
 tags
so it doesn't wrap the lines, and for the one-click select all feature.

Delete files older than _X_ days

Postby Xander » Mon Feb 17, 2014 5:40 pm

I've just added this to my D7ShutdownScript to clean up my Ninite folder.

It's running from D7II\Scripts so paths are kept relative.
Code: Select all
REM Delete files older than 30 days
Cd..
Cd "\3rd Party Tools\Custom Apps\NiniteDownloads\"
forfiles /p "Files" /s /d -30 /c "cmd /c del @file : date >= 30 days >NUL"
REm back to D7II folder
Cd..\..\..
User avatar
Xander
 
Posts: 660
Joined: Fri Feb 08, 2013 6:08 pm
Location: Near Niagara Falls

Re: Delete files older than _X_ days

Postby Nick » Tue Mar 11, 2014 12:27 pm

nice!
Author of d7x and other PC technician's tools. http://www.d7xTech.com

Image
User avatar
Nick
Site Admin
 
Posts: 2786
Joined: Mon Nov 19, 2012 7:54 pm

Re: Delete files older than _X_ days

Postby Xander » Tue Mar 11, 2014 7:36 pm

Caution - I'm having mixed results with this. The first few runs were flawless and then it would do the "cd" command with a "folder not found" error and then the ForFiles would run godknowswhere and basically hang.
User avatar
Xander
 
Posts: 660
Joined: Fri Feb 08, 2013 6:08 pm
Location: Near Niagara Falls


Return to Automation / Scripting / Batch Files