我正在尝试查找重复的 .txt 文件内容。在这种情况下,.txt 文件中的数字。 例如,
1.txt
有以下数字:1, 2, 3
,2.txt
有4, 5, 6
,3.txt
有1, 2, 3
,4.txt
有7, 8, 9
程序应该指出1.txt
与3.txt
相同。
这就是我现在所拥有的,但是有一个问题。 例如,该文件指出相同的文件
1.txt
和 1.txt
,而不是 1.txt
和 3.txt
,有什么办法可以解决这个问题吗?
setlocal enabledelayedexpansion
set "output_file=duplicates.txt"
echo Process started!
echo Please be patient, this may take some moments.
rem Delete the output file if it already exists
if exist "%output_file%" del "%output_file%"
rem Get a list of all .txt files in the current directory
for %%F in (*.txt) do (
rem Check if the file has already been processed
if not defined file[%%~nF] (
rem Read the content of the file into a variable
set "content="
for /f "usebackq delims=" %%L in ("%%F") do set "content=!content!%%L"
rem Compare the content with other .txt files
for %%G in (*.txt) do (
rem Check if the file is different, not already processed, and not self-comparison
if /i not "%%~nxF"=="%%~nF" if not defined file[%%~nxF] (
rem Read the content of the other file into a variable
set "other_content="
for /f "usebackq delims=" %%M in ("%%G") do set "other_content=!other_content!%%M"
rem Compare the content of the two files
if "!content!"=="!other_content!" (
echo "%%F" = "%%G" >> "%output_file%"
set "file[%%~nF]=true"
set "file[%%~nxF]=true"
)
)
)
)
)
rem Display the results
cls
echo Finished!
echo Here are your results:
type "%output_file%"
pause
endlocal