Batch file to delete files older than N days

前端 未结 24 2471
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 11:11

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

24条回答
  •  旧巷少年郎
    2020-11-21 12:01

    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"
    

提交回复
热议问题