如何使用批处理文件复制(和增量)文件的多个实例 [英] How to Copy (and increment) Multiple Instances of a File Using Batch File

查看:1030
本文介绍了如何使用批处理文件复制(和增量)文件的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个复制文件的批处理文件,并将其放在目标位置时递增。示例。

I need to create a batch file that copies a file and increments it upon placing it at the destination. Example.

copy C:\TEMP\MyDoc.txt E:\MyData\

基本上,我需要这个复制命令来复制每次我开始它(它现在只是罚款)。我想它增加文件名,而不是覆盖它。如果我运行这三次或100次(不是特定数字),我想在MyData文件夹中看到:

Essentially, I need this copy command to copy every time I start it (which it does now just fine). I would like it to increment the file name instead of overwrite it though. If I ran this three times or 100 times (never a certain number) I would like to see on the "MyData" folder:

MyDoc.txt

MyDoc.txt

MyDoc(1).txt

MyDoc(1).txt

...

复制(1)我不确定什么语法是一个重复的文件,我也不必关心。我只是想确保我不会覆盖在我的跳跃驱动器上的预先存在的文件。

Or Copy (1) I'm not really sure what the syntax is for a duplicated file nor do I necessarily care. I just want to ensure that I'm not overwriting the pre-existing file on my jump drive.

捕获是我在一个Allen Bradley PanelView Plus那是老和运行Windows CE。

The catch is I'm doing this on an Allen Bradley PanelView Plus that is old and running Windows CE. Any help would be greatly appreciated.

推荐答案

您可以这样尝试:

@echo off
set Source=C:\TEMP\MyDoc.txt
set Destination=E:\MyData\
set Filename=MyDoc
set a=1

:loop
if exist %Destination%\%Filename%(%a%).txt set /a a+=1 && goto :loop
copy %Source% %Destination%\%Filename%(%a%).txt
pause

这篇关于如何使用批处理文件复制(和增量)文件的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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