回复 2# 77七
一楼表达不严谨,抱歉。
个别 "*(1).pdf",是独一份的,还不能删除。
豆包生成了个,80那里不会改。- for /r "%dir%" %%F in (*.*) do (
- set "file=%%~nF"
- set "size=%%~zF"
- rem 检查是否已经处理过这个大小的文件
- if defined sizes[!size!] (
- rem 检查文件名相似度
- set "similar=false"
- for %%A in (!sizes[!size!]!) do (
- if "!file!"=="%%~nA" (
- set "similar=true"
- goto :skip
- ) else (
- call :isSimilar "!file!" "%%~nA"
- if!similarity! geq 80 (
- set "similar=true"
- goto :skip
- )
- )
- )
- if!similar! equ false (
- set "sizes[!size!]=!sizes[!size!]! %%F"
- )
- ) else (
- set "sizes[!size!]=%%F"
- )
- :skip
- )
-
- rem 遍历所有大小分组,删除除第一个文件外的其他文件
- for /f "tokens=2 delims==" %%A in ('set sizes[') do (
- set "count=0"
- for %%B in (%%A) do (
- if!count! equ 0 (
- set "firstFile=%%B"
- ) else (
- del "%%B"
- )
- set /a count+=1
- )
- )
-
- echo Done.
- pause
- goto :eof
-
- :isSimilar
- set "str1=%~1"
- set "str2=%~2"
- set "similarity=0"
- for /l %%I in (1,1,20) do (
- set "char1=!str1:~%%I,1!"
- set "char2=!str2:~%%I,1!"
- if defined char1 if defined char2 (
- if "!char1!"=="!char2!" (
- set /a similarity+=5
- )
- ) else (
- goto :eof
- )
- )
- goto :eof
复制代码
|