Update log:
V4:
1. Increased the calculation of the progress of the display;
2. Find a new version of the Md5sum.exe, there is no reliance on dynamic library.
Tool One: Md5comv4.bat accepts two directory parameters, calculates the MD5 value of each file in two directories, and gives the report file Md5v4.txt, using the method:
Md5omv4.bat < directory 1> < directory 2>
Based on this md5comv4.bat generated report file Md5v4.txt, you can find two directories
1: The same name and MD5 the same document;
2: The same name but MD5 different documents;
3: Does not have the same name but MD5 the same document;
4: Different names in the same directory but MD5 the same file.
Note:
1:md5comv4.bat does not accept directory names with spaces on the path, but can accept filenames with spaces;
The calculation of 2:MD5 is done by Md5sum.exe;
The 3:md5comv4.bat runtime produces a large number of temporary files that are automatically maintained by the tool and do not need to be cleaned manually.
This tool is command-line, text interface, for people who are accustomed to using graphical interface, may be inconvenient, therefore, do not recommend the habit of using a graphical interface with friends.
Copy Code code as follows:
@echo off
setlocal enableextensions Enabledelayedexpansion
REM Author: rubble@126.com
REM 17:55 2009-4-14 version: 0.4
Set Dira=%~1
Set dirb=%~2
If "%1" = = "" (
echo Usage instructions: Please indicate two directories on the command-line arguments, or enter them as prompted here.
echo command line parameter format: Batch Name ^< directory 1^> ^< directory 2^>
Echo.
set/p dira= Please enter the first directory name (drag and drop and enter the carriage return):
)
Echo.
If "%2" = = "" (
echo Usage instructions: Please indicate two directories on the command-line arguments, or enter them as prompted here.
echo command line parameter format: Batch Name ^< directory 1^> ^< directory 2^>
Echo.
set/p dirb= Please enter the name of the second directory (drag and drop and enter a carriage return):
)
If "%dira%" = "exit/b"
If "%dirb%" = "exit/b"
For/f "delims=. Tokens=1 '%%a in ('%time% ') do set starttime=%%a
For/f "delims=: tokens=1,2,3"%%a in ("%starttime%") Do (
Set Starth=%%a
Set Startm=%%b
Set starts=%%c
)
Set Tempdir=tempmd5\
rd/q/S%tempdir% 1>nul 2>nul
MD%tempdir%
Set Mdfive=md5v4.txt
REM Number of files processed
Set count=0
Total number of files in rem folder%dira% and%dirb%
Set total_count=0
REM number of temporary files processed
Set tmpf_count=0
The total number of REM temporary files is known to be 5. The rest is the number of MD5 values.
Set tmpf_total_count=5
echo 1th/2 step, please wait while the calculation is in progress ...
ECHO is comparing the MD5 values of files in%dira% and%dirb% >%mdfive%
Set LIST_FN_MD=%TEMPDIR%LIST_FN_MD
Set LIST_FN_NMD=%TEMPDIR%LIST_FN_NMD
Set List_fn_oa=%tempdir%list_fn_oa
Set List_fn_ob=%tempdir%list_fn_ob
Set LIST_ALL_MD=%TEMPDIR%LIST_ALL_MD
Call:countfiles%dira%
Call:countfiles%dirb%
for/f "delims="%%a in (' Dir/b/a:-d "%dira%\*" ') Do (
Set Fn=%%~nxa
for/f "Tokens=1 delims="%%a in (' Md5sum "%dira%\%%a" ') do set mda=%%a
set/a count=!count!+1
Call:P rogress!count!!total_count!
If "!mda:~0,1!" = = "\" Set mda=!mda:~1,1024!
REM with!mda! As file name, record MD5 as!mda! of the file
CALL:ADDMDFN "%tempdir%!mda!" "%dira%\!fn!"
REM records the MD5 value in the file, guaranteeing no repetition.
Call:addmdlist!mda!
If exist "%dirb%\!fn!" (
for/f "Tokens=1 delims="%%a in (' Md5sum "%dirb%\!fn!") Do set mdb=%%a
set/a count=!count!+1
CALL:ADDMDFN "%tempdir%!mdb!" "%dirb%\!fn!"
Call:P rogress!count!!total_count!
If "!mdb:~0,1!" = = "\" Set mdb=!mdb:~1,1024!
If "!mda!" = = "!mdb!" (
REM Record file name is the same and MD5 the same file
echo!mda!!mdb!!fn! >> "!list_fn_md!"
) Else (
REM record file with same file name but MD5
echo!mda!!mdb!!fn! >> "!list_fn_nmd!"
Call:addmdlist!mdb!
)
) Else (
REM records only files that appear in%dira%
Echo!mda!!fn! >> "!list_fn_oa!"
)
)
for/f "delims="%%a in (' Dir/b/a:-d "%dirb%\*" ') Do (
Set Fn=%%~nxa
If not exist "%dira%\!fn!" (
for/f "Tokens=1 delims="%%a in (' Md5sum "%dirb%\%%a" ') do set mdb=%%a
If "!mdb:~0,1!" = = "\" Set mdb=!mdb:~1,1024!
REM records only files that appear in%dirb%
Echo!mdb!!fn! >> "!list_fn_ob!"
REM records the MD5 value in the file, guaranteeing no repetition.
Call:addmdlist!mdb!
CALL:ADDMDFN "%tempdir%!mdb!" "%dirb%\!fn!"
set/a count=!count!+1
Call:P rogress!count!!total_count!
)
)
Echo 2nd/2 is being counted, please wait ...
Echo Statistics: >>%mdfive%
Echo Left:%dira% >>%mdfive%
echo Right:%dirb% >>%mdfive%
If not exist "%list_fn_md%" set/a tmpf_total_count-=1
If not exist "%list_fn_nmd%" set/a tmpf_total_count-=1
If not exist "%list_fn_oa%" set/a tmpf_total_count-=1
If not exist "%list_fn_ob%" set/a tmpf_total_count-=1
If not exist "%list_all_md%" set/a tmpf_total_count-=1
All of the echo two directories exist and MD5 the same file:>>%mdfive%
Call:outputlist "%list_fn_md%"
echo ===============================================================================================>>% Mdfive%
Echo Left:%dira% >>%mdfive%
echo Right:%dirb% >>%mdfive%
There are files in the Echo two directories, but MD5 are not the same:>>%mdfive%
Call:outputlist "%list_fn_nmd%"
echo ===============================================================================================>>% Mdfive%
echo only files that exist in the directory%dira%:>>%mdfive%
Call:outputlist "%list_fn_oa%"
echo ===============================================================================================>>% Mdfive%
echo only files that exist in the directory%dirb%:>>%mdfive%
Call:outputlist "%list_fn_ob%"
echo ===============================================================================================>>% Mdfive%
The list of files summarized by ECHO in MD5:>>%mdfive%
CALL:OUTPUTLIST_MD "%list_all_md%"
Goto Alldone
The number of files in the REM statistics folder, and put them in the global variable Total_count.
: Countfiles
If%1== "" goto:eof
for/f%%a in (' dir/b/a:-d%~1\* ') do (
set/a total_count=!total_count!+1
)
Goto:eof
REM parameter%1 must be enclosed in double quotes
: outputlist
If%1 = = "" Goto:eof
If not exist%1 goto:eof
Set tcnt=0
for/f "Tokens=1* delims="%%a in (%~1) do (
echo%%a%%b >>%mdfive%
set/a tcnt+=1
)
Echo!tcnt! >>%mdfive%
set/a tmpf_count+=1
Call:P rogress!tmpf_count!!tmpf_total_count!
Goto:eof
REM parameter%1 must be enclosed in double quotes
: OUTPUTLIST_MD
If%1 = = "" Goto:eof
If not exist%1 goto:eof
set/a tmpf_count+=1
Call:P rogress!tmpf_count!!tmpf_total_count!
Set md_count=0
for/f "Tokens=1* delims="%%a in (%~1) do (
echo%%a >>%mdfive%
Set tcnt=0
for/f "Tokens=1* delims="%%a in (!) tempdir!%%a) Do (
echo%%a%%b >>%mdfive%
set/a tcnt+=1
)
set/a tmpf_count+=1
Call:P rogress!tmpf_count!!tmpf_total_count!
Echo!tcnt! >>%mdfive%
set/a md_count+=1
Echo. >>%mdfive%
)
echo%md_count% >>%mdfive%
Goto:eof
rem Function: Save the MD5 value to a named!list_all_md! of documents,
REM and ensures that duplicate MD5 values are not saved
: addmdlist
If%1 = = "" Goto:eof
If exist "!list_all_md!" (
REM Here the delims is either deleted or made like this line, with a space following the equals sign
REM for/f "Tokens=1 delims="%%a in (!list_all_md!) Do (
for/f "Tokens=1"%%a in (!list_all_md!) Do (
If "%%a" = = "%1" goto:eof
)
)
Echo%1 >> "!list_all_md!"
Total REM Log temporary files
set/a tmpf_total_count+=1
Goto:eof
rem function: Save%2 with%1 as filename
Rem% 1: In this application is the MD5 value
rem%2:md5 file with a value of%1
: ADDMDFN
If%1 = = "" Goto:eof
If%2 = = "" Goto:eof
Echo%2 >>%1
Goto:eof
:P rogress
Set tips=
Set backspace=
set/a percent=%1*100/%2
set/a char=%1%%7
set/a BNUM=%PERCENT%/10
set/a snum=10-%bnum%
FOR/L%%a in (1, 1,%bnum%) do Set/p=▌<nul
FOR/L%%a in (1, 1,%snum%) do set/p= <nul
set/p=%1/%2%percent%%% <nul
Set/p=!tips:~%char%,1!<nul
If "%percent%" = = "100" (
Echo.
Goto:eof
)
Set/p=%backspace%<nul
Goto:eof
REM:P rogress
REM Set tips=
REM Set backspace=
REM set/a char=%1%%7
REM Set/p=!tips:~%char%,1!<nul
REM Set/p=%backspace%<nul
REM goto:eof
: Alldone
rd/q/S%tempdir% 1>nul 2>nul
For/f "delims=. Tokens=1 '%%a in ('%time% ') do set endtime=%%a
For/f "delims=: tokens=1,2,3"%%a in ("%endtime%") Do (
Set Endh=%%a
Set Endm=%%b
Set ends=%%c
)
If "%endm:~0,1%" = = "0" Set endm=%endm:~1,1%
If "%ends:~0,1%" = = "0" Set ends=%ends:~1,1%
For/f "delims=: tokens=1,2,3"%%a in ("%starttime%") Do (
Set Starth=%%a
Set Startm=%%b
Set starts=%%c
)
If "%startm:~0,1%" = = "0" Set startm=%startm:~1,1%
If "%starts:~0,1%" = = "0" Set starts=%starts:~1,1%
set/a totaltime=%endh%*3600+%endm%*60+%ends%-(%starth%*3600+%startm%*60+%starts%)
Echo is%totaltime% seconds in total.
echo Start time:%starth%:%startm%:%starts%>>%mdfive%
Echo End Time:%endh%:%endm%:%ends%>>%mdfive%
Echo is%totaltime% seconds in total. >>%mdfive%
Start%mdfive%
Echo
Endlocal
@echo on
File package Download