【问题标题】:Pass a parameterized folder name to command line将参数化的文件夹名称传递给命令行
【发布时间】:2013-04-02 08:04:14
【问题描述】:

我使用以下命令行:

调用 run.bat TEST.properties

在 TEST.properties 文件中我初始化以下参数

output.dir=C:/Test_Results

我希望“Test_Results”在每次调用脚本时都包含一个时间戳。我怎样才能做到这一点?谢谢!

【问题讨论】:

    标签: command-line batch-file command-line-arguments


    【解决方案1】:

    在 TEST.properties.bat 之后

    output.dir=C:\Test_Results
    

    插入一行

    echo %date% %time% >>%output.dir%\my_timestamps.txt
    

    TEST.properties.bat 运行的最新日期/时间将出现在C:\Test_Results\my_timestamps.txt

    请注意,/ 是一个开关指示器。 \ 是一个目录分隔符。

    【讨论】:

      【解决方案2】:

      如果您在“Test_Results”中只需要 1 个时间戳:

      set test=%1
      
      rem insert timestamp generating code below if needed
      
      set timestamp=%time%
      
      for /f "tokens=1,2* delims==" %%i in (%test%) do (if "%%i"=="output.dir" echo %timestamp%>%%j)
      

      如果您需要所有时间戳:

      set test=%1
      
      rem insert timestamp generating code below if needed
      
      set timestamp=%time%
      
      for /f "tokens=1,2* delims==" %%i in (%test%) do (
        if "%%i"=="output.dir" (
          if not exist %%j (echo %timestamp%>%%j) else (
            echo %timestamp%>temp.txt
            copy %%j+temp.txt %%j
            del temp.txt
          )
        )
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-16
        • 1970-01-01
        • 2010-11-30
        • 1970-01-01
        • 2013-03-08
        • 1970-01-01
        相关资源
        最近更新 更多