简体   繁体   English

批处理/ Windows命令行-文件比较然后打开Chrome

[英]Batch/Windows Command Line - File compare then open chrome

In batch/windows CMD: 在批处理/ Windows CMD中:
I know how to compare files and how to open chrome. 我知道如何比较文件以及如何打开Chrome。
Just how do I make an IF statement for these conditions? 我该如何针对这些情况做出IF声明?

If file1 == file2 -> dirToChrome.exe 如果file1 == file2-> dirToChrome.exe
If file1 != file2 -> exit 如果file1!= file2->退出

EDIT: They are html files containing either a 0 or a 1 编辑:它们是包含0或1的html文件

What is file1 and file2? 什么是file1和file2? (a hash of the files, a filename etc ?) (文件的哈希,文件名等?)

To compare 2 strings (file names, file hash for example): 要比较2个字符串(例如文件名,文件哈希):

set file1=%1
set file2=%2

IF %file1% EQU %file2% (
    dirToChrome.exe
)ELSE (
    exit
)

Based on c-toesca's answer, here is the code: 根据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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM