本帖最后由 xp3000 于 2021-4-21 09:24 编辑
同样大小容易误删,这个根据MD5删除,包含子文件夹也不保留第二个
想到如果强行关闭,下次可能回造成误删,在结尾和开头都添加了删除log- @cd "%~dp0"
- @echo off&setlocal enabledelayedexpansion
- del /F /S /Q "%~dp0*.log"&cls
- for /f "delims=" %%a in ('dir /a-d /b /s *.JPG *.BMP *.PNG') do (
- for /f "delims=" %%b in ('certutil -hashfile "%%a" MD5^|findstr /V 哈希^|findstr /V 完成') do (
- set "MD5=%%b"&set MD5=!MD5:^ =!&echo !MD5!-%%a|sort /+1>>"%~dp0!MD5!.log"
- for /f "tokens=1,*delims=-" %%i in ('findstr /n /i "!MD5!" !MD5!.log^|findstr /v "^1:"') do (
- del "%%j" 2>nul
- )
- )
- )
- del /F /S /Q "%~dp0*.log"&cls
- echo 删除完成
- pause
复制代码 如果子文件夹不处理,将dir /a-d /b /s改为dir /b/a-d/oN
结合楼下直接这个在临时文件夹处理- @echo off&setlocal enabledelayedexpansion
- @cd "%~dp0"&if exist "%temp%\MD5" del "%temp%\MD5\*.log" >nul 2>nul
- for /f "delims=" %%a in ('dir /a-d /b /s *.*') do (
- for /f "delims=" %%b in ('certutil -hashfile "%%a" MD5^|findstr /r /be /c:"[0-9a-f][0-9a-f ]*"') do (
- set "MD5=%%b"&set MD5=!MD5:^ =!&echo !MD5!-%%a|findstr "!MD5!"|sort /+1 >>"%temp%\MD5\!MD5!.log"
- for /f "tokens=1,*delims=-" %%i in ('findstr /n /i "!MD5!" "%temp%\MD5\!MD5!.log"^|findstr /v "^1:"') do del "%%j" 2>nul
- )
- )
- for /f "tokens=*" %%k in ('dir/s/b/ad^|sort /r') do rd "%%k" >nul 2>nul& del "%temp%\MD5\*.log" >nul 2>nul&echo 删除完成
- pause
复制代码
|