2015-08-28 53 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 –

相關問題