Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: ####### by [email protected] ( ProtectPages.com ) ###### ::
- :: This script makes a symlink of any file/dir ( instructions at: https://www.protectpages.com/blog/easiest-method-create-symlink-symbolic/ )
- ::if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
- @echo off
- setlocal enableextensions enabledelayedexpansion
- set original_path=%~1
- set original_path_quoted="%original_path%"
- if "%original_path%"=="" ( mshta "javascript:alert('You should drag desired file onto this');close();" && exit )
- :: if directory
- FOR %%i IN (%original_path_quoted%) DO IF EXIST %%~si\NUL (
- for /D %%i in (%original_path_quoted%) do SET original_drive=%%~di
- for /D %%i in (%original_path_quoted%) do SET original_dir=%original_drive%%%~pi
- for /f "delims=" %%i in (%original_path_quoted%) do SET original_basename=%%~ni
- )
- :: if file
- FOR %%i IN (%original_path_quoted%) DO IF NOT EXIST %%~si\NUL (
- for /f "delims=" %%i in (%original_path_quoted%) do SET original_drive=%%~di
- for /f "delims=" %%i in (%original_path_quoted%) do SET original_dir=%original_drive%%%~pi
- for /f "delims=" %%i in (%original_path_quoted%) do SET original_basenameWithExt=%%~nxi
- )
- set /P inputed_target_dir= Path to folder, wherein the symlink will be created:
- set inputed_target_dir=%inputed_target_dir%\
- for /D %%i in ("%inputed_target_dir%") do SET target_drive=%%~di
- for /D %%i in ("%inputed_target_dir%") do SET target_dir=%target_drive%%%~pi
- set isSameDrive=0
- IF /I "%original_drive%"=="%target_drive%" ( set isSameDrive=1 )
- :: if same ditectories, then use prefix name
- set prefix=
- IF /I "%original_dir%"=="%target_dir%" ( set prefix=_symlinked_ )
- :: if same drives, then allow user to choose HARD method. Otherwise, only SOFT can be used
- set type=2
- if %isSameDrive%==1 ( set /P type= Type 1 to use [Hard-Link], otherwise press ENTER and the default [Soft-link] will be used : )
- :: if directory
- FOR %%i IN (%original_path_quoted%) DO IF EXIST %%~si\NUL (
- IF "%type%"=="1" (
- mklink /J "%target_dir%\%prefix%%original_basename%" %original_path_quoted%
- ) ELSE (
- mklink /D "%target_dir%\%prefix%%original_basename%" %original_path_quoted%
- )
- )
- :: if file
- FOR %%i IN (%original_path_quoted%) DO IF NOT EXIST %%~si\NUL (
- IF "%type%"=="1" (
- mklink /H "%target_dir%\%prefix%%original_basenameWithExt%" %original_path_quoted%
- ) ELSE (
- mklink "%target_dir%\%prefix%%original_basenameWithExt%" %original_path_quoted%
- )
- )
- :: mshta "javascript:alert('error: creating Hard-Symlink for different drives has failed');close();"
- mshta "javascript:alert('Finished');close();"
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment