@ECHO OFF
SETLOCAL
SET "dir1=."
SET "dir2=.\e"
SET "report1=u:\existinfirstnotsecond.txt"
SET "report2=u:\smallerinsecond.txt"
DEL "%report1%" 2>NUL >nul
DEL "%report2%" 2>NUL >nul
FOR /f "delims=" %%i IN ('dir /b /a-d "%dir1%\*"') DO (
IF EXIST "%dir2%\%%i" (
FOR %%q IN ("%dir1%\%%i") DO FOR %%s IN ("%dir2%\%%i") DO (
CALL :sizes %%~zq %%~zs "%%i"
)
) ELSE (
>>"%report1%" ECHO %%i
)
)
GOTO :EOF
:sizes
IF %2 GEQ %1 GOTO :EOF
IF %2 equ 0 SET "diff= LOTS"&GOTO report
SET /a diff=%1 - %2
SET /a diff=%diff%*10000/%1
IF %diff% LSS 500 GOTO :EOF
SET diff= %diff%
SET diff=%diff:~-4,2%.%diff:~-2%
:report
>>"%report2%" ECHO %diff%%% %~3
GOTO :eof
これにより、必要な結果が得られるはずです。dir1,dir2,report1
との設定を置き換えるだけです。report2
最初のファイル名が 2 番目のディレクトリに存在する場合は、両方のサイズとファイル名を procedure に送信します:sizes
。そうでない場合は、見つかったが 2 番目のディレクトリにないファイルの名前を に書き込みます。report1
最初のサイズが 2 番目のサイズ以上の場合は報告しないでください。2 番目のファイルの長さが 0 の場合、%diff は無限大です。それ以外の場合は、差を計算し、10000 を掛けて割ります。最初のファイルのサイズによる結果。結果は 0..10000 です。500 は 5% を意味し、5% 未満の場合は無視し、それ以外の場合は先頭にスペースを追加し、ドットを挿入して差を報告します。
唯一の問題は、ファイルが 200K を超える場合に発生する可能性があり、数学をもう少し洗練する必要があります (バッチは 32 ビットの符号付き整数に制限されます)。
20130625-1958Z を編集 - For..%%i /%%q/%%s ループはオリジナルを置き換え、ディレクトリ名が見つからない問題を修正しました。
Edit 20130626-1601Z -SIZES
長いファイルの置換ルーチン
:sizes
:: establish the file sizes
SET siz1=%1&SET siz2=%2
:szloop
:: Size of file 1 insanely less than size of file 2 ?
IF NOT DEFINED siz1 GOTO :EOF
:: Size of file 2 insanely less than size of file 1 ?
IF NOT DEFINED siz2 SET "diff= LOTS"&GOTO report
:: keep peeling the last digit from the sizes until
:: neither is more than 5 digits long
IF NOT %siz1:~5%%siz2:~5%x==x SET siz1=%siz1:~0,-1%&SET siz2=%siz2:~0,-1%&GOTO szloop
:: Now use SIZ1 and SIZ2
IF %siz2% GEQ %siz1% GOTO :EOF
IF %siz2% equ 0 SET "diff= LOTS"&GOTO report
SET /a diff=siz1 - siz2
SET /a diff=%diff%*10000/siz1
IF %diff% LSS 500 GOTO :EOF
SET diff= %diff%
SET diff=%diff:~-4,2%.%diff:~-2%
:report
>>"%report2%" ECHO %diff%%% %~3
GOTO :eof