-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlink.bat
executable file
·74 lines (61 loc) · 1.57 KB
/
symlink.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@echo OFF
REM Author: Josh Jaques.
REM Copyright: Josh Jaques, 2011. All rights reserved.
REM set xp=true for XP mode, false for vista/win7 mode
REM xp mode requires that you have junction on your path
REM Download from here: http://download.sysinternals.com/Files/Junction.zip
REM Extract to C:\Windows\System32
set xp=false
:read_params
if [%1] EQU [] (
goto :usage
) ELSE (
REM note %~1 = 1 without quotes
set target=%~1
)
if [%2] EQU [] (
goto :usage
) ELSE (
set link_name=%~2
)
:verify_params
if NOT EXIST "%target%" (goto :invalid_target)
if EXIST "%link_name%" (goto :invalid_link)
:print_params
echo Using target: "%target%"
echo Using linkname: "%link_name%"
:main
REM Check if target is a directory
if EXIST %target%\ (
goto :link_directory
) else (
goto :link_file
)
goto :eof
:link_directory
echo Doing directory link
if %xp% EQU true (
echo Using XP Mode
junction "%link_name%" "%target%" > NUL
) else (
mklink /d "%link_name%" "%target%" > NUL
)
goto :eof
:link_file
cho Doing file link
if %xp% EQU true (
echo Using XP Mode
fsutil hardlink create "%link_name%" "%target%" > NUL
) else (
mklink "%link_name%" "%target%" > NUL
)
goto :eof
:usage
echo Usage: [target] [link_name]
goto :eof
:invalid_target
echo Target "%target%" does not exist
goto :eof
:invalid_link
echo Link "%link_name%" already exists
goto :eof