【问题标题】:Windows batch script: Perform a command if two files are the same!Windows 批处理脚本:如果两个文件相同,则执行命令!
【发布时间】:2011-02-26 00:41:12
【问题描述】:

我原以为这将是一项非常简单的任务,但我已经为此苦苦挣扎了几天,有点沮丧!我对 Windows 批处理脚本不是很熟悉,所以如果你知道答案,请尽可能简单:)

基本上,我有一个 Windows 关机脚本(.bat 文件),我想知道两个文本文件是否相同(即它们的内容完全相同),如果是,则执行 goto 命令(例如转到第 10 行)

我不知道该怎么做!非常感谢您的帮助!

【问题讨论】:

标签: windows file batch-file compare


【解决方案1】:

没有转到:

fc /b file1 file2 > nul
if errorlevel 1 (
    echo different
) else (
    echo same
)

【讨论】:

  • 请注意if errorlevel 1 actually means that errorlevel is 1 or moreFC 如果其中一个文件不存在,则设置错误级别 2。所以第一种情况真的是echo different, or at least one doesn't exist
【解决方案2】:

这个脚本应该可以工作:

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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多