将文件移动到新目录的批处理命令
我想编写一个批处理作业,执行时将抓取 C:\Test\Log 文件夹中的所有文件并将它们移动到 C:\Test 中的新目录>。这个新目录的名称为“Backup-”,名称为“当前日期”。
因此,完成后,日志文件夹应该为空,所有文件现在都位于新文件夹中。
我知道我必须使用 MOVE 命令,但不知道如何动态创建新文件夹并使用日期来命名它。
I want to write a batch job that when executed will grab all the files in the C:\Test\Log
folder and move them to a new directory in the C:\Test
. This new directory will have a name called "Backup-" and CURRENT DATE.
So once completed, the log folder should be empty with all the files now located in the new folder.
I know I would have to use the MOVE
command, but have no idea how to dynamically create a new folder, and use the date to name it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样的事情可能会有所帮助:
重要的部分是第一行。它获取内部
DATE
值的输出,并将其解析为名为Today
的环境变量,格式为CCYYMMDD
,如“20110407” 。%Date:~10,4%
表示提取Date
环境变量“Thu 04/07/2011”的*子字符串(内置 - 类型在命令提示符处 echo %Date%
),从位置 10 开始,共 4 个字符 (2011
)。然后,它将Date:
的另一个子字符串从位置 4 开始连接 2 个字符 (04
),然后连接从位置 7 开始的两个附加字符 (07
)代码>)。*子字符串值起始点从0开始。
您可能需要根据您所在区域的日期格式调整这些值,但这应该为您提供一个起点。
Something like this might help:
The important part is the first line. It takes the output of the internal
DATE
value and parses it into an environmental variable namedToday
, in the formatCCYYMMDD
, as in '20110407`.The
%Date:~10,4%
says to extract a *substring of theDate
environmental variable 'Thu 04/07/2011' (built in - typeecho %Date%
at a command prompt) starting at position 10 for 4 characters (2011
). It then concatenates another substring ofDate:
starting at position 4 for 2 chars (04
), and then concats two additional characters starting at position 7 (07
).*The substring value starting points are 0-based.
You may need to adjust these values depending on the date format in your locale, but this should give you a starting point.
如果你愿意的话,这也可以
this will also work, if you like