Guest User

Untitled

a guest
May 30th, 2026
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.05 KB | Source Code | 0 0
  1. :: CloneTree.cmd v0.1 March 12, 2016
  2. @ECHO OFF
  3. CHCP 65001 >NUL
  4. SETLOCAL EnableExtensions DisableDelayedExpansion
  5. SET "targetDir=%~dpn0"
  6. SET "sourceDir=%~dp0"
  7. SET "SELF=%~nx0"
  8. SET fileCnt=0
  9. IF NOT "%~1"=="" (
  10.     SET "targetDir=%~dpn0\%~nx1"
  11.     SET "sourceDir=%~1"
  12. )
  13.  
  14. :dirCheck
  15. IF "%sourceDir:~-1%"=="\" SET "sourceDir=%sourceDir:~0,-1%" &GOTO :dirCheck
  16. IF "%targetDir:~-1%"=="\" SET "targetDir=%targetDir:~0,-1%" &GOTO :dirCheck
  17. TITLE scanning: "%sourceDir%\*"
  18. FOR /F "tokens=*" %%A IN ('DIR /A-D-S /B /S "%sourceDir%\*" 2^>NUL ^| SORT') DO CALL :ct "%%A"
  19. ECHO.%~nx0 cloned %fileCnt% files, press any key to exit...
  20. TITLE %~nx0 cloned %fileCnt% files.
  21. ENDLOCAL
  22. PAUSE >NUL
  23. EXIT /B 0
  24.  
  25. :ct
  26. SET "fn=%~1"
  27. CALL SET "fn=%%fn:%sourceDir%\=%%"
  28. IF "%fn%"=="%SELF%" EXIT /B 0
  29. IF NOT EXIST "%targetDir%\%fn:^=^^%" ( TITLE cloning: "\%fn%"
  30.     CALL MD "%targetDir%\%%fn:%~nx1=%%" >NUL 2>&1
  31.     IF /I "%targetDir:~0,2%"=="%~d1" ( MKLINK /H "%targetDir%\%fn:^=^^%" %1 >NUL 2>&1
  32.     ) ELSE REM.>"%targetDir%\%fn:^=^^%"
  33.     SET /A fileCnt+=1)
  34. EXIT /B 0
  35.  
  36. ::by CirothUngol
Tags: batch
Advertisement
Add Comment
Please, Sign In to add comment