Batch File to remove Old Files

This script uses ForFiles to remove old files based on age. However, you must have forfiles installed. Windows 2003 and above have it by default

 

The Syntax is: 

FORFILES -p "Path to the folder" -s -m *.txt -d   -c "cmd /c del @path"

 

Example:

REM  Delete all BAK files from folder C:\backup  that are 5 days or older

FORFILES -p "C:\backup" -s -m *.bak -d -5 -c "cmd /c del @path"

 

 

Want a job to do this automatically? See

SQL Job to delete old files

Leave a Reply

Your email address will not be published. Required fields are marked *