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

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

问题描述

我需要创建一个批处理文件来复制文件并在将其放置到目标位置时增加它.示例.

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

copy C:TEMPMyDoc.txt E:MyData

本质上,我每次启动时都需要这个复制命令进行复制(现在它做得很好).我希望它增加文件名而不是覆盖它.如果我运行了 3 次或 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(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.

问题是我在运行 Windows CE 的旧版 Allen Bradley PanelView Plus 上执行此操作.任何帮助将不胜感激.

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:TEMPMyDoc.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天全站免登陆