DOS下比較兩個文件的大小

首先建立一個批處理文件,命名爲comparesize.bat.

@echo off
rem 比較兩個文件的大小,返回較大文件的編號,相同返回0.
set file1=%1
set file2=%2
dir /-c %file1%>comparetemp1.txt
dir /-c %file2%>comparetemp2.txt
findstr /c:"1 個文件" comparetemp1.txt>sizetemp1.txt
findstr /c:"1 個文件" comparetemp2.txt>sizetemp2.txt
setlocal EnableDelayedExpansion
for /f "tokens=3 delims= " %%i in (sizetemp1.txt) do (
set /a size1=%%i
)
for /f "tokens=3 delims= " %%i in (sizetemp2.txt) do (
set /a size2=%%i
)
del comparetemp1.txt
del comparetemp2.txt
del sizetemp1.txt
del sizetemp2.txt
if !size1! gtr !size2! (
exit /b 1
) else if !size1! lss !size2! (
exit /b 2
) else (
exit /b 0
)

然後再建立一個批處理文件來調用它,把它命名爲test.bat

@echo off
call comparesize.bat No1filepath No2filepath
echo %errorlevel%
pause

echo將會輸出較大文件的編號,相同的時候輸出0.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章