Page 1 of 1

How to act on the difference of two files?

Posted: 14 Feb 2006 13:27
by Jan de Ruiter
I want to write:
if these two files are different
then do this piece of code
else do that piece of code
endif

I know fc (filecompare) does not give an exit code
depending on de difference of the files.

In UNIX I would write
if cmp file1 file2
then echo files are equal
else echo files are not equal
fi

How do I do this in dos?

Posted: 18 Feb 2006 20:22
by DosItHelp
In WinXP fc does return an exit code and you could use:

Code: Select all

fc "%file1%" "%file2%">NUL&&(
    echo the files are equal
    rem keep this rem as last command in the block
)||(
    echo the files are different
)


However if the fc command in your windows version works different then you can try:

Code: Select all

fc "%file1%" "%file2%"|find "*****">NUL&&(
    echo the files are different
    rem keep this rem as last command in the block
)||(
    echo the files are equal
)

Posted: 02 Mar 2006 03:45
by Jan de Ruiter
Thanks, that was very helpful

Re: How to act on the difference of two files?

Posted: 13 Jul 2011 08:51
by Ed Diarrhea
What is the difference between fc and comp? :shock: