Skip to content

Instantly share code, notes, and snippets.

@jatubio
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jatubio/6744f762d7de5d14046e to your computer and use it in GitHub Desktop.
Save jatubio/6744f762d7de5d14046e to your computer and use it in GitHub Desktop.
Clone source to destination using ln.exe
@echo off
setlocal enabledelayedexpansion
setlocal
set DestinationDrive=Z
set includeDir=
goto :include
:main
call :source "%~1"
rem echo source set to %source% from %~1
call :destination "%~2" "%source%"
rem echo destination set to %destination% from %~2 and %source%
if [%source%]==[] (
echo El origen está vacío
goto :EOF
)
if [%destination%]==[] (
echo El destino está vacío
goto :EOF
)
set info=Cloning "%source%" into "%destination%"
if defined includeDir set info=%info% with params: %includeDir%
echo %info%
pause Press a key to continue
rem for /D %%a in (%1\*.*) do "C:\App\Files\Links Tools\ln\ln.exe" --backup --copy "%%a" "%2\%%~na"
rem for /D %%a in (%1\*.*) do echo "C:\App\Files\Links Tools\ln\ln.exe" --backup --copy %%a %2%%~na
call :clone "%source%" "%destination%"
endLocal
goto :EOF
:include
set include=false
if [%1]==[-I] set include=true
if [%1]==[-i] set include=true
if %include%==true (
set includeDir=%includeDir% --includedir "%~2"
shift
shift
goto :include
)
goto :main
:clone
rem if not exist "%~2\%~n1" echo "C:\App\Files\Links Tools\ln\ln.exe" --backup --copy "%~1" "%~2\%~n1"
echo Cloning...(This may take a while)
if defined includeDir (
"C:\App\Files\Links Tools\ln\ln.exe" %includeDir% --backup --copy "%~1" "%~2"
) else (
"C:\App\Files\Links Tools\ln\ln.exe" --backup --copy "%~1" "%~2"
)
rem rd /s /q "%~1"
goto :EOF
:source
set source=%CD%
IF not [%~1]==[] (
set source=%~1
)
goto :EOF
:destination
IF NOT [%~1]==[] (
SET destination=%~1
) else (
set destination=%DestinationDrive%:%~pn2
)
goto :EOF
@jatubio
Copy link
Author

jatubio commented Jun 21, 2015

Add -i parameter to pass include dirs.

Usage:

cloneln [-i includedir] [-i includedir] ... [source] [destination]

Samples:

  • Clone current directory on %DestinationDrive% same name folder.
K:\PowerBackup\Dev\Proyectos>cloneln
K:\PowerBackup\Dev\Proyectos>cloning K:\PowerBackup\Dev\Proyectos onto Z:\PowerBackup\Dev\Proyectos
  • Clone current directory on %DestinationDrive% same name folder.
K:\PowerBackup\Dev\Proyectos>cloneln
K:\PowerBackup\Dev\Proyectos>cloning K:\PowerBackup\Dev\Proyectos onto Z:\PowerBackup\Dev\Proyectos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment