About FC /B - for very large files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kero
Posts: 16
Joined: 12 Jul 2016 00:49
Location: Moscow

About FC /B - for very large files

#1 Post by kero » 20 Feb 2017 18:47

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 ?
Last edited by kero on 22 Feb 2017 02:19, edited 2 times in total.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: About FC /B - for very large files

#2 Post by miskox » 21 Feb 2017 04:37

One way would be to redirect output to NUL

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

kero
Posts: 16
Joined: 12 Jul 2016 00:49
Location: Moscow

Re: About FC /B - for very large files

#3 Post by kero » 21 Feb 2017 05:36

> 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...

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: About FC /B - for very large files

#4 Post by miskox » 21 Feb 2017 06:59

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

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: About FC /B - for very large files

#5 Post by Aacini » 21 Feb 2017 09:22

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

kero
Posts: 16
Joined: 12 Jul 2016 00:49
Location: Moscow

Re: About FC /B - for very large files

#6 Post by kero » 21 Feb 2017 14:49

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)
Attachments
fc_b_2_large_files.7z
(1.27 KiB) Downloaded 544 times

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: About FC /B - for very large files

#7 Post by Aacini » 22 Feb 2017 13:32

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.

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

kero
Posts: 16
Joined: 12 Jul 2016 00:49
Location: Moscow

Re: About FC /B - for very large files

#8 Post by kero » 23 Feb 2017 01:15

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 ??

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: About FC /B - for very large files

#9 Post by Squashman » 23 Feb 2017 07:23

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.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: About FC /B - for very large files

#10 Post by misol101 » 23 Feb 2017 16:53

Very inventive solution Aacini. Cool!

Post Reply