【问题标题】:Replace and cut or nested replace (x2) in one line (batch-file)在一行中替换和剪切或嵌套替换(x2)(批处理文件)
【发布时间】:2015-11-22 23:58:10
【问题描述】:

如何在一个命令行中将当前日期和时间转换为不带空格的文件名?

我知道怎么做两行:

set file_name=file_%date%-%time:~0,2%%time:~3,2%%time:~6,2%
rem echo %file_name% return "file_2015-08-01- 85012" and it's not ok 

(包含空格)

set file_name=%file_name: =0%
echo echo %file_name% return "file_2015-08-01-085012" and it's ok

(无空格)

但我无法在 *.bat 文件中运行程序 - 我必须运行“原始”*.exe,这需要一行中的所有参数。

【问题讨论】:

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


【解决方案1】:
for /f "tokens=1-6 delims=:/- " %a in ('robocopy "|" . /njh^|find "|"') do echo %a-%b-%c-%d%e%f

【讨论】:

  • 它应该作为参数之一传递给*.exe程序。您不能将“for ...”作为参数传递 - 一种解决方案是传递“file_%date%-%time:~0,2%%time:~3,2%%time:~6,2%”,但是我想要“0”而不是“”(空格)。
  • @jakson,这个想法不是使用exefile for /f ...,而是使用for /b ..... exefile file_%a-%b-%c-%d%e%f。在前面的代码中,将echo 替换为可执行文件
猜你喜欢
  • 1970-01-01
  • 2010-09-19
  • 2018-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-08
  • 1970-01-01
相关资源
最近更新 更多