@echo off setlocal enabledelayedexpansion

rem 创建待删除目录 mkdir "待删除xx"

rem 创建测试文件 echo "test file 1" > "test1.txt" echo "test file 2" > "test2.txt" echo "test file 3" > "test3.txt" echo "test file 4" > "test4.txt" echo "test file 5" > "test5.txt" echo "test file 6" > "test6.txt" echo "test file 7" > "test7.txt" echo "test file 8" > "test8.txt" echo "test file 9" > "test9.txt" echo "test file 10" > "test10.txt"

rem 查找重复文件 set "found=0" for /r %%f in (*) do ( set "filename=%%~nxf" set "filepath=%%~dpf" set "filelist=!filelist!%%f;" )

set "filename=" set "filepath=" for /f "tokens=1,2 delims=;" %%a in ('echo !filelist!') do ( if "%%b" neq "!filepath!" ( set "filename=%%~nxa" for /f "tokens=1,* delims=;" %%c in ('echo !filelist! ^| find /i "%%~nxa;"') do ( if "%%d" neq "!filepath!" ( set "found=1" echo "%%~nxa" >> "待删除xx\123.txt" ) ) ) )

if !found! equ 0 ( echo "没有找到重复文件。" )

rem 删除重复文件 for /f "tokens=1 delims=" %%f in ('type "待删除xx\123.txt"') do ( del "%%f" echo "已删除文件 %%f。" )

rem 删除测试文件 del *.txt rmdir "待删除xx" /s /q

echo "脚本执行完毕。


原文地址: https://www.cveoy.top/t/topic/emzf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录