Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: CloneTree.cmd v0.1 March 12, 2016
- @ECHO OFF
- CHCP 65001 >NUL
- SETLOCAL EnableExtensions DisableDelayedExpansion
- SET "targetDir=%~dpn0"
- SET "sourceDir=%~dp0"
- SET "SELF=%~nx0"
- SET fileCnt=0
- IF NOT "%~1"=="" (
- SET "targetDir=%~dpn0\%~nx1"
- SET "sourceDir=%~1"
- )
- :dirCheck
- IF "%sourceDir:~-1%"=="\" SET "sourceDir=%sourceDir:~0,-1%" &GOTO :dirCheck
- IF "%targetDir:~-1%"=="\" SET "targetDir=%targetDir:~0,-1%" &GOTO :dirCheck
- TITLE scanning: "%sourceDir%\*"
- FOR /F "tokens=*" %%A IN ('DIR /A-D-S /B /S "%sourceDir%\*" 2^>NUL ^| SORT') DO CALL :ct "%%A"
- ECHO.%~nx0 cloned %fileCnt% files, press any key to exit...
- TITLE %~nx0 cloned %fileCnt% files.
- ENDLOCAL
- PAUSE >NUL
- EXIT /B 0
- :ct
- SET "fn=%~1"
- CALL SET "fn=%%fn:%sourceDir%\=%%"
- IF "%fn%"=="%SELF%" EXIT /B 0
- IF NOT EXIST "%targetDir%\%fn:^=^^%" ( TITLE cloning: "\%fn%"
- CALL MD "%targetDir%\%%fn:%~nx1=%%" >NUL 2>&1
- IF /I "%targetDir:~0,2%"=="%~d1" ( MKLINK /H "%targetDir%\%fn:^=^^%" %1 >NUL 2>&1
- ) ELSE REM.>"%targetDir%\%fn:^=^^%"
- SET /A fileCnt+=1)
- EXIT /B 0
- ::by CirothUngol
Advertisement
Add Comment
Please, Sign In to add comment