我怎样才能在批处理文件比较两个文件? [英] How can I compare two files in a batch file?

查看:176
本文介绍了我怎样才能在批处理文件比较两个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何比较在批处理文件中两个文件,​​并执行基于他们是否匹配的动作?我已经试过类似:

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命令,然后检查ERRORLEVEL。下面是一些code:

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

(从<一把拉住href=\"http://www.computing.net/answers/dos/batch-file-command/15753.html\">http://www.computing.net/answers/dos/batch-file-command/15753.html)

这篇关于我怎样才能在批处理文件比较两个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆