@echo off
chcp 65001 >nul
setlocal EnableDelayedExpansion
REM 定义变量
set "file1=file1.txt"
set "file2=file2.txt"
set "outputFile=result.txt"
set "tempFile1=temp1.txt"
set "tempFile2=temp2.txt"
REM 清空输出文件
> "%outputFile%" echo.
REM 提取并排序文件中的MD5值
for /F "usebackq tokens=*" %%a in ("%file1%") do (
set "line=%%a"
set "path=!line:~0,-32!"
set "md5=!line:~-32!"
echo !md5! !path! >> "%tempFile1%"
)
for /F "usebackq tokens=*" %%a in ("%file2%") do (
set "line=%%a"
set "path=!line:~0,-32!"
set "md5=!line:~-32!"
echo !md5! !path! >> "%tempFile2%"
)
sort "%tempFile1%" /O "%tempFile1%"
sort "%tempFile2%" /O "%tempFile2%"
REM 比较文件
set "countSame=0"
set "countDiff=0"
echo 相同md5文件: >> "%outputFile%"
for /F "tokens=1,* delims= " %%a in (%tempFile1%) do (
find "%%a" "%tempFile2%" >nul
if !errorlevel! equ 0 (
echo txt1中的路径: %%b >> "%outputFile%"
for /F "tokens=1,* delims= " %%c in ('find "%%a" "%tempFile2%"') do (
echo txt2中的路径: %%d >> "%outputFile%"
)
echo md5值: %%a >> "%outputFile%"
echo. >> "%outputFile%"
set /A countSame+=1
)
)
echo. >> "%outputFile%"
echo 不同md5文件: >> "%outputFile%"
for /F "tokens=1,* delims= " %%a in (%tempFile1%) do (
find "%%a" "%tempFile2%" >nul
if !errorlevel! neq 0 (
echo txt中的路径: %%b >> "%outputFile%"
echo md5值: %%a >> "%outputFile%"
echo. >> "%outputFile%"
set /A countDiff+=1
)
)
REM 输出结果统计
set /A countSame=%countSame%
set /A countDiff=%countDiff%
echo 相同md5文件一共有 %countSame% 个 >> "%outputFile%"
echo. >> "%outputFile%"
echo 不同md5文件一共有 %countDiff% 个 >> "%outputFile%"
REM 显示结果文件
type "%outputFile%"
REM 清理临时文件
del "%tempFile1%"
del "%tempFile2%"
endlocal
pause