简体   繁体   English

使用BAT命令复制并重命名新文件

[英]Copy and rename the new file using BAT command

I have a file in C:\\ folder which is the following: 我在C:\\文件夹中有一个文件,如下所示:

My_File_mmddyyyy_hhmmss.txt

The file's mmddyy_hhmmss will change based on the date and time the file is generated. 文件的mmddyy_hhmmss将根据生成文件的日期和时间进行更改。 How can I create a batch file which will copy that file to C:\\TEST\\ and rename the copied file to My_File_mmddyy.txt (drop the _hhmmss from the file name)? 如何创建批处理文件,将其复制到C:\\TEST\\并将重命名的文件重命名为My_File_mmddyy.txt (从文件名中删除_hhmmss )?

since the date and time changes in the filename, can I do something like this: 由于文件名中的日期和时间发生了变化,我可以这样做吗?

@ECHO OFF
xcopy /s c:\My_File_*.txt c:\TEST\My_File_mmddyyyy.txt

But then the original mmddyyyy will disappear. 但是随后原始的mmddyyyy将消失。

How can I achieve what I am looking to do? 我该如何实现自己的目标?

The command COPY (among others) has this bit of little-known functionality: COPY命令(除其他外)具有以下鲜为人知的功能:

COPY My_File_*.txt My_File_????????.txt

The eight question marks in the new name will result in the mmddyyyy part of the source being exactly preserved. 新名称中的八个问号将导致源的mmddyyyy部分被完全保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM