Reputation: 119
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?
Upvotes: 2
Views: 1522
Reputation: 67216
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%"
Upvotes: 3