Delete files older then "X" days old through a command line

cyrusuncc used Ask the Experts™
I'm looking for a program that will delete files in a specified folder older then, say a week old.  I need the program to be launched from a command prompt, and the output must be through the command prompt.  Reason being is i'm logging the deletion, and monitoring how much is building up.  I've found a program that works, but the output is not in the command window so i can't capture it into a text file.

Here's the software that works:

I'd prefer a free tool, or at least one with a free trial.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
A rather uncommon, but easy to realize possibility which would remove old files as well as giving you a detailed log how many files and which file size had been deleted would be through robocopy.
Use robocopy to move the files to a folder "Garbage" or whatever, then simply delete the "Garbage" folder. robocopy has extensive log functions, can append to or recreate the log file, can check for a minimum file age.

Windows Server 2003 Resource Kit Tools

So all you'd need is a little script, for example like this:

@echo off
robocopy "C:\Old Files\" "C:\Garbage\" *.* /s /mov /create /minage:7 /log:"C:\Log Files\DelOld.log"
rd C:\Garbage /s /q

"/s" processes subdirectories (if necessary), "/mov" will move the files after the copy, and to speed things up as well as save space, you can use the "/create" switch; this will not copy the file's content, but just create the folders and files with a size of zero bytes. /minage:7 will only copy files that are at least 7 days old. "/log" will log what happened (/log+... would append to an existing log file).
Other switches (how much to log, for example) are described by robocopy /? and in robocopy.doc in the installation folder.


Thanks, i'm going to take a look at this.  I think it will work for my purposes!

great share! I was looking for such a tool!


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial