制作一个在发生名称冲突时保留两个文件的批处理文件 [英] Make a Batch File That Keeps Both Files When a Name Conflict Occurs

查看:67
本文介绍了制作一个在发生名称冲突时保留两个文件的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以制作一个在名称冲突时不会覆盖现有文件,而是将文件的两个副本都放在同一路径中的批处理文件?

Is there any way to make a batch file that does not overwrite an existing file when there is a name conflict, but instead keeps both copies of the file in the same path?

推荐答案

下面的批处理文件就像COPY命令一样,只有一个文件.如果该文件已存在于目标文件夹中,则将括号中的数字添加到新文件中以保留两个文件.

The Batch file below works like COPY command with just one file. If the file already exist in target folder, a number in parentheses is added to new file in order to keep both files.

@echo off
Rem mycopy sourceFile targetDir
Set targetName=%~1
Set i=0
:nextName
   If not exist "%~2/%targetName%" goto copy
   Set /A i+=1
   Set targetName=%~1 (%i%)
   Goto nextName
:copy
Copy %1 "%~2/%targetName%"

这篇关于制作一个在发生名称冲突时保留两个文件的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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