About FC /B - for very large files
Moderator: DosItHelp
About FC /B - for very large files
Hi !
FC.EXE can compare very large files (more than 4 gb),
but here is the question about excessive delay in identifying files inequality:
does FC.EXE has (an undocumented) key to complete the work immediately after finding the first mismatch ?
Or is it possible to get the same result in some other way ?
FC.EXE can compare very large files (more than 4 gb),
but here is the question about excessive delay in identifying files inequality:
does FC.EXE has (an undocumented) key to complete the work immediately after finding the first mismatch ?
Or is it possible to get the same result in some other way ?
Last edited by kero on 22 Feb 2017 02:19, edited 2 times in total.
Re: About FC /B - for very large files
One way would be to redirect output to NUL
if ERRORLEVEL returns 1 there is a mismatch.
Also if file sizes are not the same ERRORLEVEL is 1.
Another way would be using a 3rd party software: for example md5.exe or similar and then you can compare these MD5 hashes.
Saso
Code: Select all
C:\fc /b file1.exe file2.exe>nul
if ERRORLEVEL returns 1 there is a mismatch.
Also if file sizes are not the same ERRORLEVEL is 1.
Another way would be using a 3rd party software: for example md5.exe or similar and then you can compare these MD5 hashes.
Saso
Re: About FC /B - for very large files
> One way would be to redirect output to NUL
This way does not win time: ERRORLEVEL returns 1 not after first mismatch, but only after the end of scan...
This way does not win time: ERRORLEVEL returns 1 not after first mismatch, but only after the end of scan...
Re: About FC /B - for very large files
Of course. Redirection to NUL would cause the FC command to complete faster than displaying everything to the screen or writing to a file.
Saso
Saso
Re: About FC /B - for very large files
Code: Select all
@echo off
setlocal
fc /B file1.exe file2.exe 2>NUL | (set /P "line=" & call echo %%line%% > firstLine.txt)
echo The first output line from FC command is:
type firstLine.txt
This Batch file ends as soon as FC command output its first line; after that, you may process the first line stored in the file to get the result...
Antonio
Re: About FC /B - for very large files
Antonio, very good idea,
but your variant above is not working as it should
(at least - in my case only, Windows 7):
again - not after first mismatch, but after full scan...
(attachment: files for test)
but your variant above is not working as it should
(at least - in my case only, Windows 7):
again - not after first mismatch, but after full scan...
(attachment: files for test)
- Attachments
-
- fc_b_2_large_files.7z
- (1.27 KiB) Downloaded 539 times
Re: About FC /B - for very large files
Ok. There are a couple details that needs to be adjusted in this method. In the very first place, we need to take the second line from FC output, not the first one; if this line is "FC: No differences encountered" the files are equal. If there is at least one difference, then the right side of the pipe ends immediately; however, the left side will end until the next line be output from FC.exe. Of course, if there are not more differences, then the left side of the pipe will end until FC.exe ends. For this reason, the FC.exe process must be killed with TASKKILL command as soon as the first difference appear.
Also, the first SET /P command at right side of the pipe must execute before the left side start outputting lines in order to avoid the synchro problems that happen now and then in these cases, so it is convenient to insert a delay before FC command start run. The Batch file below have all these points fixed.
Antonio
Also, the first SET /P command at right side of the pipe must execute before the left side start outputting lines in order to avoid the synchro problems that happen now and then in these cases, so it is convenient to insert a delay before FC command start run. The Batch file below have all these points fixed.
Code: Select all
@echo off
setlocal
echo Comparing files
( ping -n 2 localhost >NUL & fc /b "_0(0)0" "_1(0)2" 2>NUL ) | (
set /P "line=" & set /P "line="
call echo %%line%% > result.txt
for /F "skip=3 tokens=2" %%a in ('tasklist /FI "IMAGENAME eq fc.exe"') do @taskkill /F /PID %%a >NUL
)
for /F %%a in (result.txt) do (
if "%%a" equ "FC:" (
echo FC: No differences encountered
) else (
echo Files are different
)
)
Antonio
Re: About FC /B - for very large files
Super! Usage ping here - for me this is a wonderful instructive example, many thanks, Antonio!
P.S. But mystery: after all why the author of FC did not provide the obvious key for immediate exit after the first mismatch ??
P.S. But mystery: after all why the author of FC did not provide the obvious key for immediate exit after the first mismatch ??
Re: About FC /B - for very large files
kero wrote:P.S. But mystery: after all why the author of FC did not provide the obvious key for immediate exit after the first mismatch ??
You seriously want to go there. You do realize it was written by someone at Microsoft. That in itself should tell you something. I usually blame it on all the Peyote they smoked when the company was first located in New Mexico.
Re: About FC /B - for very large files
Very inventive solution Aacini. Cool!