【问题标题】: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
)
【解决方案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]