Symlinks, variously called junctions, hardpoints and whatever else, exist on Windows. On Linux, it is simply ln.
These are my notes for Windows 10.
Note that if you want to do any of this in a .cmd file, then you will need to elevate permissions. See Running a batch file as administrator on Windows 10.
- Git on Windows has ln, but it does not work.
-
Babun supports it.
- Maybe this means Cygwin does, too.
Detect if symlinking is enabled ∞
fsutil.exe behavior query SymlinkEvaluation
Enable symlinking ∞
Local to local symlinks:
fsutil.exe behavior set SymlinkEvaluation L2L:1
Checking for a symlink ∞
As usual, you can append things like /S
Of any sort ∞
dir.exe /A:L
Directories ∞
dir.exe /A:DL
Files ∞
dir.exe /A:-DL
Processing symlinks ∞
To "do stuff" with symlinked files, you'd use a FOR
loop. Below are some examples, but you can copy-paste any of the dir.exe
code from above. Don't forget to append /B
for 'bare' format, to omit the header and summary.
All files which are symlinks:
FOR /F %%i in ( 'dir.exe /A:-DL /B' ) DO (
ECHO " * Processing %%i"
)
A particular file which is a symlink:
FOR /F %%i in ( 'dir.exe /A:-DL /B symlink_filename.ext' ) DO (
ECHO " * Processing %%i"
)
TODO - knowing if a file exists or not ∞
I didn't take the time to learn this.
TODO - doing stuff if a file/dir is a symlink ∞
I didn't take the time to learn this.
Creating symlinks ∞
You will need to elevate the privilege of your batch file. See Running a batch file as administrator on Windows 10
Creating a symlinked directory ∞
- Fixed path:
SET SOURCE_DIRECTORY="C:\Users\user\source_directory" SET TARGET_DIRECTORY="C:\Users\user\target_directory" mklink /J %TARGET_DIRECTORY% %SOURCE_DIRECTORY%
- From the commandline's current directory:
SET SOURCE_DIRECTORY="source_directory" SET TARGET_DIRECTORY="target_directory" mklink /J %TARGET_DIRECTORY% %SOURCE_DIRECTORY%
- From a batch file's current directory:
SET "SOURCE_DIRECTORY=%~dp0source_directory" SET TARGET_DIRECTORY="target_directory" mklink /J %TARGET_DIRECTORY% %SOURCE_DIRECTORY%
SET SOURCE_DIRECTORY="%CD%\source_directory" SET TARGET_DIRECTORY="target_directory" mklink /J %TARGET_DIRECTORY% %SOURCE_DIRECTORY%
Many directories and files ∞
- create
go.cmd
- In that same directory, have files and directories
-
The intent is to add in
target_directory
symlinks to those files and folders where thatgo.cmd
script lives.
@ECHO OFF
:: For each directory and file found, make a symlink to a specified directory.
::
:: Tested 2016-07-20 on Windows 10, updated recently.
::
:: https://blog.spiralofhope.com/?p=13539:: This requires a trailing slash.
SET "SOURCE_DIRECTORY=%~dp0"
SET "TARGET=C:\Users\user\"NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (
ECHO Right-click and run this as administrator.
PAUSE
EXIT /B)
CD %SOURCE_DIRECTORY%
:: Directories
FOR /D %%i in ( *.* ) DO (ECHO * Processing %SOURCE_DIRECTORY%%%i
ECHO %TARGET_DIRECTORY%%%i
mklink /J "%TARGET_DIRECTORY%%%i" "%SOURCE_DIRECTORY%%%i")
:: Files
FOR %%i in ( *.* ) DO (IF NOT "%%i"=="go.cmd" (
ECHO * Processing %SOURCE_DIRECTORY%%%i
ECHO %TARGET_DIRECTORY%%%i
mklink "%TARGET_DIRECTORY%%%i" "%SOURCE_DIRECTORY%%%i"
))
Caveats ∞
explorer.exe's favorites sidebar refreshing ∞
explorer.exe
has a sidebar on the left.
If any of those favorites were deleted as files and then re-created as symlink targets.
Restart explorer.exe
to refresh that list.
for Geany ∞
Geany has an obnoxious issue which I have not solved.
- I make a symlink
-
I confirm confirm the symlink was a success. Ways:
- Variously editing (with
notepad.exe
) its source and target and conforming the change appears in both places. - Opening the target's directory in
explorer.exe
, ensuring 'type' is enabled as a column, then checking that the presumed-symlinked file is listed as '.symlink'.
- Variously editing (with
- I edit the source with Geany. I confirm the target changes.
-
I edit the target with Geany. The source does not change because Geany will overwrite the symlink with a normal file, breaking the symlink.
Other stuff ∞
- https://bitsum.com/portfolio/junctionmaster/
- Winbolic Link for 98/ME/2000/XP (any editions)
- How to redirect user shell folders to a specified path by using Profile Maker
- Redirecting the target of My Documents folder
- How to redirect a directory in Windows 10
-
Link Shell Extension (LSE)
- ... provides for the creation of Hardlinks, Junctions, Volume Mountpoints, and Windows7/8's Symbolic Links, a folder cloning process that utilises Hardlinks or Symbolic Links and a copy process taking care of Junctions, Symbolic Links, and Hardlinks.
Last updated 2021-03-11 at 01:51:40
dumped a few links
Added Link Shell Extension. Thanks to Mark Rousell.