views:

1478

answers:

2

Hello everyone! I recently found this site and thought I might try it out because it seemed very unique.

How can I compare two files in a batch file, and perform an action based on whether or not they match? I've tried something like:

if file1.txt NEQ file2.txt goto label

but it compares the actual string "file1.txt" rather than the file. I've read about the COMP command, but it doesn't seem to work if I put it in an if statement. Does anybody know how to do this? Sorry, but I rarely use batch files and have little experience in them.

Thanks in advance,

Cory Walker

A: 

It seems like the COMP program is actually fairly easy to use. See this question on Yahoo answers.

Note that running comp /? will print the help text for the program (as does specifying the /? argument with any native Windows command line program). This outputs the same text you see in the answer of the question linked above.

Noldorin
+3  A: 

I believe you can use the "FC" command and then check the errorlevel. Here's some code:

@echo off
:main
fc c:\filename r:\filemame > nul
if errorlevel 1 goto error

:next
echo insert next CD
pause
goto main

:error
echo failed check

(Pulled from http://www.computing.net/answers/dos/batch-file-command/15753.html)

turdfurguson