【问题标题】:Batch/Windows Command Line - File compare then open chrome批处理/Windows 命令行 - 文件比较然后打开 chrome
【发布时间】: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


    【解决方案1】:

    根据 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
    )
    

    【讨论】:

      【解决方案2】:

      file1 和 file2 是什么? (文件的哈希,文件名等?)

      比较两个字符串(例如文件名,文件哈希):

      set file1=%1
      set file2=%2
      
      IF %file1% EQU %file2% (
          dirToChrome.exe
      )ELSE (
          exit
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-12
        • 1970-01-01
        • 2010-11-29
        • 1970-01-01
        • 1970-01-01
        • 2020-09-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多