Batch file to delete files older than N days

前端 未结 24 3206
没有蜡笔的小新
没有蜡笔的小新 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 11:52

    More flexible way is to use FileTimeFilterJS.bat:

    @echo off
    
    ::::::::::::::::::::::
    set "_DIR=C:\Users\npocmaka\Downloads"
    set "_DAYS=-5"
    ::::::::::::::::::::::
    
    for /f "tokens=* delims=" %%# in ('FileTimeFilterJS.bat  "%_DIR%" -dd %_DAYS%') do (
        echo deleting  "%%~f#"
        echo del /q /f "%%~f#"
    )
    

    The script will allow you to use measurements like days, minutes ,seconds or hours. To choose weather to filter the files by time of creation, access or modification To list files before or after a certain date (or between two dates) To choose if to show files or dirs (or both) To be recursive or not

提交回复
热议问题