I am looking for a way to delete all files older than 7 days in a batch file. I\'ve searched around the web, and found some examples with hundreds of lines of code, and oth
Enjoy:
forfiles -p "C:\what\ever" -s -m *.* -d -c "cmd /c del @path"
See forfiles documentation for more details.
For more goodies, refer to An A-Z Index of the Windows XP command line.
If you don't have forfiles
installed on your machine, copy it from any Windows Server 2003 to your Windows XP machine at %WinDir%\system32\
. This is possible since the EXE is fully compatible between Windows Server 2003 and Windows XP.
Later versions of Windows and Windows Server have it installed by default.
For Windows 7 and newer (including Windows 10):
The syntax has changed a little. Therefore the updated command is:
forfiles /p "C:\what\ever" /s /m *.* /D - /C "cmd /c del @path"