批处理命令将文件移动到一个新的目录 [英] Batch command to move files to a new directory
问题描述
我想编写一个批处理作业,当执行时会抢在C中的所有文件:\\测试\\ Log文件夹并将其移动到一个新的目录在c:\\测试。这个新的目录将有一个名为备份 - 和当前日期的名字。
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 will all the files now located in the new folder.
我知道我将不得不使用MOVE命令,但不知道如何动态地创建一个新的文件夹,并使用日期来命名它。
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.
推荐答案
像这样的东西可能有帮助:
Something like this might help:
SET Today=%Date:~10,4%%Date:~4,2%%Date:~7,2%
mkdir C:\Test\Backup-%Today%
move C:\Test\Log\*.* C:\Test\Backup-%Today%\
SET Today=
重要的部分是第一行。它采用内部日期
值的输出并将其解析为一个名为环境变量今天
,格式为 CCYYMMDD
,如'20110407`。
The important part is the first line. It takes the output of the internal DATE
value and parses it into an environmental variable named Today
, in the format CCYYMMDD
, as in '20110407`.
的%日期:10.4〜%
说,提取日期的*子
环境变量周四04/07/2011(建于 - 键入在命令提示符处回声%DATE%
)开始位置10的4个字符( 2011
)。然后,它并置日期的另一个子:
开始在第4位的2个字符( 04
),然后的邻接两个附加起始位置7( 07
)。
The %Date:~10,4%
says to extract a *substring of the Date
environmental variable 'Thu 04/07/2011' (built in - type echo %Date%
at a command prompt) starting at position 10 for 4 characters (2011
). It then concatenates another substring of Date:
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.
这篇关于批处理命令将文件移动到一个新的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!