批处理方式实现的目录比较工具

2019-09-19 06:56:23丽君


goto ALLDONE

rem 统计文件夹里的文件数目,放到全局变量 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 参数 %1 必须加双引号
: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 :PROGRESS !tmpf_count! !tmpf_total_count!
goto :EOF

rem 参数 %1 必须加双引号
:OUTPUTLIST_MD
if %1 == "" goto :EOF
if not exist %1 goto :EOF

set /a tmpf_count+=1
call :PROGRESS !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 :PROGRESS !tmpf_count! !tmpf_total_count!
echo !tcnt! >> %mdfive%
set /a md_count+=1
echo. >> %mdfive%
)
echo %md_count% >> %mdfive%
goto :EOF

rem 函数:把 md5 值保存到一个名为 !list_all_md! 的文件里,
rem 并保证不保存重复的 md5 值
:ADDMDLIST
if %1 == "" goto :EOF
if exist "!list_all_md!" (
rem 这里的 delims 要么删除,要么做成像下面这行的样子,在等号后面加个空格
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!"
rem 记录临时文件总数
set /a tmpf_total_count+=1
goto :EOF

rem 函数:以 %1 为文件名,保存 %2
rem %1:在这个应用里是 md5 值
rem %2:md5 值为 %1 的文件
:ADDMDFN
if %1 == "" goto :EOF
if %2 == "" goto :EOF
echo %2 >> %1
goto :EOF

:PROGRESS
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 :PROGRESS
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%
相关文章 大家在看