2015-08-28 51 views
1

如何在一个cmd行中转换当前日期&时间转换为不带空格的文件名?在一行(批处理文件)中替换并剪切或嵌套替换(x2)

我知道该怎么做,在两行:

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文件 - 我必须运行“original”* .exe,它需要一行中的所有参数。

+0

看看这个:http://stackoverflow.com/a/19799236/388389 – npocmaka

回答

0
for /f "tokens=1-6 delims=:/- " %a in ('robocopy "|" . /njh^|find "|"') do echo %a-%b-%c-%d%e%f 
+0

应该传递到* .exe程序的参数之一。你不能通过“for ...”作为参数 - 一种解决方案是通过“file_%date% - %time:〜0.2 %% time:〜3.2 %% time:〜6,2%”,但我想“0”而不是“”(空间)。 – jakson

+0

@jakson,这个想法不是使用'exefile for/f ...',而是'for/b ..... exefile file_%a-%b-%c-%d%e%f'。在前面的代码中,用可执行文件替换echo –

相关问题