如何比较批处理文件中的两个文件? [英] How can I compare two files in a batch file?
问题描述
如何比较批处理文件中的两个文件,并根据它们是否匹配执行操作?我试过像:
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
但它比较的是实际的字符串file1.txt,而不是文件。我已经阅读过COMP命令,但它似乎不工作,如果我把它放在一个if语句。有人知道如何这样做吗?对不起,我很少使用批处理文件,并且很少有经验。
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.
提前感谢。
推荐答案
我相信你可以使用FC命令,然后检查错误级别。这里有一些代码:
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
(从 http://www.computing.net/answers/dos/batch-file-command/15753.html )
这篇关于如何比较批处理文件中的两个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!