批处理文件,用于循环处理超过一定期限的文件

时间:2019-11-09 09:23:10

标签: batch-file

有人可以帮助我使以下批处理文件仅处理365天以上的文件吗?

@echo off
SetLocal EnableDelayedexpansion

set "Folder=C:\Test Folder"
set "exclude=.dll.exe.bat.zip.jpg.bmp.pdf.mp4.vbs"

FOR /f "delims=" %%x IN ('dir /b /s "%Folder%" ') do if "!exclude:%%~Xx.=!" 
equ "%exclude%" (
"7za.exe" a -sdel -stl "%%~dx%%~px%%~nx.zip" "%%x"
)

1 个答案:

答案 0 :(得分:0)

@echo off
color 0A
SetLocal EnableDelayedexpansion

Set folder="C:\Test Folder"

Set exclude=".dll.exe.bat.zip.jpg.bmp.pdf.avi.mpg.mov.mp4.vbs.lnk"

FOR /f "delims=" %%x IN ('forfiles /p !folder! /d -365 /s /c "cmd /c echo @path"') do if "!exclude:%%~Xx.=!" equ "%exclude%" (
      "7za.exe" a -sdel -stl "%%~dx%%~px%%~nx.zip" %%x 
)