@echo off
fc c:\ABC\abc.txt c:\DEF\abc.txt > nul
if errorlevel 2 goto err2
if errorlevel 1 goto err1
if errorlevel 0 goto err0
goto exit
:err0
echo. is same
goto exit
:err1
echo. is different
goto exit
:err2
echo. file is lost
goto exit
:exit
-----------------
rem://這段編碼是用來比較檔案或資料夾的大小是否相同。
@echo off
rem://關閉指令行自身的顯示
fc c:\ABC\abc.txt c:\DEF\abc.txt > nul
rem:// fc.exe 是用來比較兩個檔案或兩組檔案並且顯示其中的不同之處。(一般在 c:\windows\system32\)
rem:// 如要比較兩個資料夾,可以變為:( fc c:\ABC\*.* c:\DEF\*.* > nul )
rem:// 如路徑有空格,應變為:( fc "c:\AB C\*.*" "c:\DE F\*.*" > nul )
rem:// 假若不加 >nul ,cpu會飆到100。>nul 用於屏蔽標準輸出在屏幕上的顯示。
if errorlevel 2 goto err2
rem://表示兩個檔案中,有一個以上是不存在
if errorlevel 1 goto err1
rem://表示兩個檔案不同
if errorlevel 0 goto err0
rem://表示兩個檔案相同
goto exit
rem://以上皆不是時直接跳到「:exit」行
:err0
rem://兩個檔案相同時執行此行
echo. They are same
goto exit
rem://直接跳到「:exit」行
:err1
echo. They are different
goto exit
:err2
echo. Some file(s) is lost
goto exit
:exit
rem://完結
沒有留言:
張貼留言