Last active
January 27, 2018 19:54
-
-
Save arieljannai/33e0fd86d0b338bbc6db to your computer and use it in GitHub Desktop.
Duplicates the given file or folder. Accept the regular copy command parameters as well
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem if you want, you can change the cp command to the regular windows copy or xcopy or whatever copy command you like | |
for %%a in (%*) do set last=%%a | |
set source_file=%last% | |
set /a count=2 | |
set all_params=%* | |
if exist "%source_file% - Copy" ( | |
call :set_first_available_name "%source_file% - Copy (%count%)" | |
) else ( | |
cp %all_params% "%source_file% - Copy" | |
) | |
goto :eof | |
:set_first_available_name | |
IF EXIST "%source_file% - Copy (%count%)" ( | |
set /a count+=1 | |
call :set_first_available_name "%source_file% - Copy (%count%)" | |
) ELSE ( | |
call :do_copy | |
) | |
goto :eof | |
:do_copy | |
cp %all_params% "%source_file% - Copy (%count%)" | |
goto :eof | |
:eof | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment