User Tools

Site Tools


computing:windows:del_files_older

This is an old revision of the document!


Delete Files Older Than X Days on Windows

http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days

http://forums.devshed.com/windows-help-34/deleting-files-older-than-14-days-using-batch-file-script-364137-2.html

This will delete all files in my backup directory older than 3 days:

forfiles -p z:\backup -s -m *.* -d -3 -c "cmd /c del /q @path"

Syntax for Windows 2008:

forfiles /P "C:\Mysql_backup" /S /M *.sql /D -30 /C "cmd /c del @PATH"

To test it first, use this:

forfiles -p z:\backup -s -m *.* -d -3 -c "cmd /C Echo 0x22@Path\@File0x22"

This will print out each file that you will be deleting.

computing/windows/del_files_older.1320696037.txt.gz · Last modified: 2011/11/07 13:00 by gcooper