问题
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?
回答1:
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%"
来源:https://stackoverflow.com/questions/14033582/make-a-batch-file-that-keeps-both-files-when-a-name-conflict-occurs