开发者

How to redirect output to a file which name is the current date and time?

I would like to redirect the output of a command (in the Win开发者_如何学JAVAdows command line) to a file which name is the current date and time. For example:

my_path\mysqldump.exe my_database_name > auto_generated_file_name

where auto_generated_file_name should be something like 2010_09_30___11_41_58.txt.

This command will automatically run from time to time. This is the reason I need the file name to be automatically generated.

What is the easiest method to achieve this ?


The following command creates a blank file with the expected filename:

> type nul > %date:~10,4%_%date:~4,2%_%date:~7,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%.txt

> dir /b
2010_09_29__22_12_44.txt

You can use the part after type nul > in place of your auto_generated_file_name.


There's a nice solution here, and it almost matches your example formatting:

set dd = %date% %Time% 
my_command > MyFile__%dd:~0,2%_%dd:~3,2%_%dd:~6,4%___%dd:~11,2%_%dd:~14,2%.txt 

Output: "MyFile__22_05_2009__6_20.txt"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜