本帖最后由 aloha20200628 于 2024-10-17 12:48 编辑
回复 1# lhw
先比较两个目标目录d1和d2的文件数量,择其少者为要遍历的基准目录d1,代码中假设两个目标目录均为绝对路径,可由楼主自定义...
- @echo off &setlocal
- set "d1=d:\abc"
- set "d2=d:\xyz"
- for /f %%n in ('dir /b/a-d "%d1%"^|find /c /v "" ') do set "n1=%%n"
- for /f %%n in ('dir /b/a-d "%d2%"^|find /c /v "" ') do set "n2=%%n"
- if %n1% gtr %n2% set "d1=%d2%" &set "d2=%d1%"
- for %%a in ("%d1%\*") do if exist "%d2%\%%~nxa" for /f "delims=" %%b in ("%d2%\%%~nxa") do if "%%~ta" lss "%%~tb" (echo,删除同名旧版本》"%%~a"&del/q "%%~a") else (echo,删除同名旧版本》"%%~b"&del/q "%%~b")
- endlocal&pause&exit/b
复制代码
|