Thursday, July 14, 2011

Copy Files and Automatically Rename Existing Ones

Usually while copying large amount of files it is necessary to rename the existing files to avoid overwriting them with the copied ones. Usual commands like copy or xcopy don't let you perform renaming in automatic mode. Still you are able to create a batch script that will help you to solve this problem:
@echo off
for %%i in (SourceDir\*) do (
if exist "DestDir\%%~nxi" (
mv "%%i" "DestDir\~%%~nxi"
) else (
mv "%%i" "DestDir"
)
)

You can change this example script according to your needs with the help of our batch files editor. Hope you'll find this small example useful.

No comments:

Post a Comment

Translate