User Tools

Site Tools


computing:windows:del_files_older

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 a backup directory older than 3 days:

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

To test it first, this will print out each file that you will be deleting:

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

Syntax for Windows 2008:

forfiles /P "C:\Mysql_backup" /S /M *.sql /D -30 /C "cmd /c del @PATH"
computing/windows/del_files_older.txt · Last modified: 2011/11/07 13:10 by gcooper