创建一个批处理文件以复制并重命名文件 [英] Create a batch file to copy and rename file

查看:93
本文介绍了创建一个批处理文件以复制并重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个批处理文件,将文件复制到新文件夹并重命名.

I need to write a batch file that copies a file to a new folder and renames it.

此刻,我的批处理文件仅包含以下命令:

At the moment, my batch file consists of only this command:

COPY ABC.PDF \\Documents

如您所见,它只会将文件ABC.pdf复制到网络文件夹Documents.

As you can see, it only copies the file ABC.pdf to the network folder Documents.

但是我需要更改它,以便它重命名文件ABCxxx.pdf,其中xxx是我想在批处理文件中的某个地方设置的文本变量.

However I need to change this so it renames the file ABCxxx.pdf, where xxx is a text variable that I would like to set somewhere in the batch file.

例如,如果xxx = _Draft,则文件在复制后将重命名为ABC_Draft.pdf.

For example, if xxx = _Draft, then file would be renamed ABC_Draft.pdf after it is copied.

推荐答案

制作一个包含以下内容的bat文件:

Make a bat file with the following in it:

copy /y C:\temp\log1k.txt C:\temp\log1k_copied.txt

但是,如果目录名中有空格,我认为会出现问题.请注意,这已复制到同一目录,但这没关系.如果要查看其运行方式,请制作另一个bat文件,该文件会调用第一个文件并输出到日志:

However, I think there are issues if there are spaces in your directory names. Notice this was copied to the same directory, but that doesn't matter. If you want to see how it runs, make another bat file that calls the first and outputs to a log:

C:\temp\test.bat > C:\temp\test.log

(假设第一个bat文件名为test.bat,并且位于该目录中)

(assuming the first bat file was called test.bat and was located in that directory)

这篇关于创建一个批处理文件以复制并重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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