How to act on the difference of two files?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jan de Ruiter
Posts: 2
Joined: 14 Feb 2006 13:18
Location: holland

How to act on the difference of two files?

#1 Post by Jan de Ruiter » 14 Feb 2006 13:27

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?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 18 Feb 2006 20:22

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
)

Jan de Ruiter
Posts: 2
Joined: 14 Feb 2006 13:18
Location: holland

#3 Post by Jan de Ruiter » 02 Mar 2006 03:45

Thanks, that was very helpful

Ed Diarrhea
Posts: 6
Joined: 01 Jul 2011 16:38

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

#4 Post by Ed Diarrhea » 13 Jul 2011 08:51

What is the difference between fc and comp? :shock:

Post Reply