11

I would have thought this was going to be a very simple task but I have been struggling with it for a couple of days now, and slightly frustrated! I am not very familiar with Windows batch scripts so please if you know the answer, keep it as simple as possible :)

Basically, I have a Windows Shutdown script (.bat file) in which I would like to know if two text files are the same (i.e. their content is exactly the same), and if so, perform a goto command (e.g. goto line10)

I can't figure out how to do this! Your help is much appreciated!

1

2 Answers 2

20

Without the goto:

fc /b file1 file2 > nul if errorlevel 1 ( echo different ) else ( echo same ) 
Sign up to request clarification or add additional context in comments.

1 Comment

Note that if errorlevel 1 actually means that errorlevel is 1 or more. FC sets errorlevel 2 if one of the files doesn't exist. So the first case really is echo different, or at least one doesn't exist.
11

This script should work:

fc /b file1 file2 > nul if errorlevel 1 goto files_differ [files are the same, do something here] :files_differ [files are not the same, do something here] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.