參考https://elderec.org/2012/02/scripting-delete-files-and-folders-older-than-x-days/
@echo off
:: set folder path
set dump_path=c:\shares\dump
:: set min age of files and folders to delete
set max_days=7
:: remove files from %dump_path%
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path"
:: remove sub directories from %dump_path%
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"
:: set folder path
set dump_path=c:\shares\dump
:: set min age of files and folders to delete
set max_days=7
:: remove files from %dump_path%
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q @path"
:: remove sub directories from %dump_path%
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF @isdir == TRUE rd /S /Q @path"
以上例子是刪除>=7天的檔案其資料夾,如果您喜歡powershell,上方網址中有提示~~~