Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows批处理脚本:如果两个文件相同,则执行命令!_Windows_File_Batch File_Compare - Fatal编程技术网

Windows批处理脚本:如果两个文件相同,则执行命令!

Windows批处理脚本:如果两个文件相同,则执行命令!,windows,file,batch-file,compare,Windows,File,Batch File,Compare,我本以为这将是一个非常简单的任务,但我已经挣扎了几天了,有点沮丧!我不太熟悉Windows批处理脚本,因此如果您知道答案,请尽量简单:) 基本上,我有一个Windows关机脚本(.bat文件),其中我想知道两个文本文件是否相同(即它们的内容完全相同),如果相同,请执行goto命令(例如goto line10) 我不知道该怎么做!非常感谢你的帮助 此脚本应该可以工作: fc /b file1 file2 > nul if errorlevel 1 goto files_differ [fil

我本以为这将是一个非常简单的任务,但我已经挣扎了几天了,有点沮丧!我不太熟悉Windows批处理脚本,因此如果您知道答案,请尽量简单:)

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


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

此脚本应该可以工作:

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]
没有后藤:

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

请注意,
如果错误级别1
<如果其中一个文件不存在,则代码>FC设置错误级别2。所以第一种情况实际上是不同的,或者至少一种情况不存在。