How do I write a batch file to delete folders and files on a time basis?

前端 未结 2 1161
醉梦人生
醉梦人生 2021-01-21 13:58

Exact Duplicates:

  • How to write a batch file to delete the files which are 5 days or older from a folder?
  • write a batch file to delete 6 days older files
2条回答
  •  失恋的感觉
    2021-01-21 14:54

    You may want to try this script to delete files from a folder that are older than 1 hour.

    # Script Delete1Hour.txt
    var str folder, list, file
    cd $folder
    lf -n "*" $folder ($ftype=="f") AND ( $fmtime < addtime(diff("-10000")) ) > $list
    while ($list <> "")
    do
        lex "1" $list > $file
        system del ("\""+$file+"\"")
    done
    

    This is biterscripting. The important command is

    lf -n "*" $folder ($ftype=="f") AND ( $fmtime < addtime(diff("-10000")) )
    

    Which tells biterscripting - give me all entries in folder $folder with names that match the patten "*" whose file type is "f" (flat file, not directory), and whose file modification time ($fmtime) is earlier than 1 hour. See the documentation for the lf command at http://www.biterscripting.com/helppages/lf.html .

    Save the script in file C:/Scripts/Delete1Hour.txt, run it as

    script  "C:/Scripts/Delete1Hour.txt" folder("C:/testfolder")
    

    It will delete all files from C:/testfolder that are older than 1 hour.

提交回复
热议问题