【发布时间】:2014-08-28 19:07:11
【问题描述】:
批处理/Windows CMD:
我知道如何比较文件以及如何打开 chrome。
我该如何针对这些条件创建 IF 语句?
如果 file1 == file2 -> dirToChrome.exe
如果 file1 != file2 -> 退出
编辑:它们是包含 0 或 1 的 html 文件
【问题讨论】:
标签: windows batch-file command-line windows-7
批处理/Windows CMD:
我知道如何比较文件以及如何打开 chrome。
我该如何针对这些条件创建 IF 语句?
如果 file1 == file2 -> dirToChrome.exe
如果 file1 != file2 -> 退出
编辑:它们是包含 0 或 1 的 html 文件
【问题讨论】:
标签: windows batch-file command-line windows-7
根据 c-toesca 的回答,代码如下:
:: These are parameters that are passed into the script
set file1=%1
set file2=%2
:: Extracting the contents of the files
for /f "tokens=1* delims=" %%c in ('type "%file1%"') do set file1_value=%%c
for /f "tokens=1* delims=" %%c in ('type "%file2%"') do set file2_value=%%c
:: Comparing the values
IF "%file1_value%" EQU "%file2_value%" (
dirToChrome.exe
) ELSE (
exit
)
【讨论】:
file1 和 file2 是什么? (文件的哈希,文件名等?)
比较两个字符串(例如文件名,文件哈希):
set file1=%1
set file2=%2
IF %file1% EQU %file2% (
dirToChrome.exe
)ELSE (
exit
)
【讨论】: