如何添加日期和时间,在DOS下文件名? [英] How to add date and time to filename in DOS?

查看:553
本文介绍了如何添加日期和时间,在DOS下文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在文件名添加日期和时间值,然后我想通过文件夹,该文件移动到附近。

I want to add date and time value in filename and then I want to move that file to near by folder.

下面我用下面的命令来捕获日期和时间:

Here I'm using below commands to capture date and time :

set dt=%date:~7,2%-%date:~4,2%-%date:~10,4%_%time:~,8%

echo %dt%

然后我使用copy命令如下:

Then I am using copy command as below :

copy result_accnum.txt C:\ramki_windows\batch_practise\Query_stored\result_accnum_%dt%.txt

但没有用。我得到的错误是文件名,目录名或卷标签语法不正确。

but nothing useful. I am getting error as "The filename, directory name, or volume label syntax is incorrect.".

推荐答案

冒号()是不允许的文件名。它保留划定的驱动器盘符等,在DOS路径名。你可以使用下划线( _ ),而不是:

The colon (:) isn't allowed in a file name. It's reserved for delimiting drive letters, etc, in DOS path names. You could use underscore (_) instead:

set dt=%date:~7,2%-%date:~4,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%

请注意,没有前导零的时间上午10点之前。如果这是你的文件名的格式重要,那么它可以做如下:

Note that there is no leading zero for times before 10 am. If this is important for your file name format, then it could be done as follows:

set hh=%time:~0,2%
if "%time:~0,1%"==" " set hh=0%hh:~1,1%   

set dt=%date:~7,2%-%date:~4,2%-%date:~10,4%_%hh%_%time:~3,2%_%time:~6,2%

这篇关于如何添加日期和时间,在DOS下文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆