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
http://www.cookingsql.com/2014/12/sql-job-to-delete-old-files/