retesere20

----reycler---symlink-creator-v1

Sep 14th, 2018
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. :: ####### by tazotodua@gmail.com ( ProtectPages.com ) ###### ::
  3. :: This script makes a symlink of any file/dir ( instructions at: https://www.protectpages.com/blog/easiest-method-create-symlink-symbolic/ )
  4.  
  5. ::if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
  6.  
  7. @echo off
  8. setlocal enableextensions enabledelayedexpansion
  9.  
  10. set original_path=%~1
  11. set original_path_quoted="%original_path%"
  12. if "%original_path%"=="" ( mshta "javascript:alert('You should drag desired file onto this');close();" && exit )
  13.  
  14. :: if directory
  15. FOR %%i IN (%original_path_quoted%) DO IF EXIST %%~si\NUL (
  16. for /D %%i in (%original_path_quoted%) do SET original_drive=%%~di
  17. for /D %%i in (%original_path_quoted%) do SET original_dir=%original_drive%%%~pi
  18. for /f "delims=" %%i in (%original_path_quoted%) do SET original_basename=%%~ni
  19. )
  20. :: if file
  21. FOR %%i IN (%original_path_quoted%) DO IF NOT EXIST %%~si\NUL (
  22. for /f "delims=" %%i in (%original_path_quoted%) do SET original_drive=%%~di
  23. for /f "delims=" %%i in (%original_path_quoted%) do SET original_dir=%original_drive%%%~pi
  24. for /f "delims=" %%i in (%original_path_quoted%) do SET original_basenameWithExt=%%~nxi
  25. )
  26.  
  27. set /P inputed_target_dir= Path to folder, wherein the symlink will be created:
  28. set inputed_target_dir=%inputed_target_dir%\
  29. for /D %%i in ("%inputed_target_dir%") do SET target_drive=%%~di
  30. for /D %%i in ("%inputed_target_dir%") do SET target_dir=%target_drive%%%~pi
  31.  
  32. set isSameDrive=0
  33. IF /I "%original_drive%"=="%target_drive%" ( set isSameDrive=1 )
  34.  
  35. :: if same ditectories, then use prefix name
  36. set prefix=
  37. IF /I "%original_dir%"=="%target_dir%" ( set prefix=_symlinked_ )
  38.  
  39. :: if same drives, then allow user to choose HARD method. Otherwise, only SOFT can be used
  40. set type=2
  41. if %isSameDrive%==1 ( set /P type= Type 1 to use [Hard-Link], otherwise press ENTER and the default [Soft-link] will be used : )
  42.  
  43. :: if directory
  44. FOR %%i IN (%original_path_quoted%) DO IF EXIST %%~si\NUL (
  45. IF "%type%"=="1" (
  46. mklink /J "%target_dir%\%prefix%%original_basename%" %original_path_quoted%
  47. ) ELSE (
  48. mklink /D "%target_dir%\%prefix%%original_basename%" %original_path_quoted%
  49. )
  50. )
  51.  
  52. :: if file
  53. FOR %%i IN (%original_path_quoted%) DO IF NOT EXIST %%~si\NUL (
  54.  
  55. IF "%type%"=="1" (
  56. mklink /H "%target_dir%\%prefix%%original_basenameWithExt%" %original_path_quoted%
  57. ) ELSE (
  58. mklink "%target_dir%\%prefix%%original_basenameWithExt%" %original_path_quoted%
  59. )
  60. )
  61.  
  62. :: mshta "javascript:alert('error: creating Hard-Symlink for different drives has failed');close();"
  63. mshta "javascript:alert('Finished');close();"
  64. endlocal
RAW Paste Data