@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
如果在第二個目錄中存在的第一個文件名的設置,同時發送的大小和文件名的程序:sizes
,否則,寫找到的文件的名稱,但在失蹤第二個目錄report1
如果第一個的大小大於或等於第二個的大小,則不報告它,如果第二個文件的長度爲0,則%diff是無限的,否則計算的差異,乘以10000並將結果除以第一個文件的大小。結果是0..10000; 500表示5%,如果小於5%則忽略它,否則添加前導空格,插入點並報告差異。
如果文件是可能出現的唯一問題> 200K,其中數學需要一點更復雜(批次被限制爲32位有符號整數)
編輯20130625-1958Z - 對於.. %%我/ %% q/%% s循環替換原來修復缺少目錄名稱的問題。
編輯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
非常感謝您的回覆!我剛剛對我的文件進行了測試,它對第一次報告非常有用,但是在secodn中,如果它給了我比較的文件名稱,那將是非常好的。我知道我需要在這裏添加文件名:>>「%report2%」ECHO%diff %%%%〜3,但不知道要寫什麼...... – user2516836
不確定需要更改哪些內容。當前正在輸出的行應該顯示諸如「10.67%文件名」這樣的行 - 它適用於我。這兩個目錄中的文件名是相同的;你知道這些目錄名是什麼 - 只有當第二個文件小於第一個文件大小的95%時纔會顯示報告。如果你想要完整的文件名,那麼使用'%dir1%\%〜3'或'%dir2%\%〜3'或者兩者來代替'%〜3'。如果你願意,在':sizes'這個標籤後面加上一行'ECHO%*'來顯示傳遞給例程的參數,這些參數可以用'%1,%2和%3'表示'〜'描述 – Magoo
我現在可以看到問題所在。參數不適合我。沒有顯示參數1,對於2和3,它分別是dir2中的文件大小和文件名。這也是爲什麼百分比值不能正確計算(因爲只有一個大小值被解析)。你知道這個問題可能是什麼嗎? – user2516836