38

Is it possible to change the target of a symlink or junction in Windows? In Linux it can be modified with:

ln -f

5 Answers 5

26

With Windows Link Shell Extension installed, you can right-click on the link in Windows Explorer and check the properties. There is a tab that allows you to change the link directly.

Sorry I can't say if this is possible without the extension installed as it is one of the first things I install after Windows.

The Windows command link tool mklink does not allow this.

There are, however, Windows equivalents for Linux commands. ln.exe is one:

5
  • This solution seems to work however I didn't test it thoroughly. Jul 23, 2012 at 9:32
  • wow! Link Shell Extension, also notably, includes a Symbolic Link Driver for Windows XP among it's downloads.
    – n611x007
    Mar 27, 2013 at 11:50
  • mklink would be the Windows-integrated command for linking (symbolic and hard).
    – Jinxed
    Feb 28, 2016 at 22:08
  • 2
    @Jinxed, I already said that mklink doesn't do what the OP asked. Feb 29, 2016 at 22:36
  • 2
    The windows Methodology for changing the location of a softlink using MKLINK is to delete the link (Using RD /Q if a directory link, or Del /F /Q if a file link) and recreate it uisang MKLINK. eg RD /Q "C:\Link\Folder" && MKLINK /D "C:\Link\Folder" "C:\Some\New\Target\Folder" and Del /F /Q "C:\Link\File Link" && MKLINK "C:\Link\File Link.ext" "C:\Some\New\Target\File here.ext" This is also True for Junctions and Hard Links. May 14, 2019 at 15:33
7

Powershell

New-Item -Type SymbolicLink -Path "C:\linkpath" -Target "C:\newtarget" -Force

Mind the -Force Luke

P.S. elevated mode required

5

Just remove and recreate the link. That's all that -f does in Linux anyway.

Also, here's a cool Windows Link Shell Extension.

3

The method belo works for me in Windows 7

mklink TempLink NewTarget

copy /l /y TempLink OldLink

del TempLink
1
  • This worked for me on Windows Server 2012 R2. The important part is copy /L which preserves symlinks.
    – Dai
    May 24, 2021 at 15:06
1

Note that if the symlink is a hanging symlink, i.e. points to a nonexistent location, then using linkshell extension will not allow you to edit the target, because this works as an extension to explorer which adds a tab to the properties context menu. If the symlink is hanging, explorer signals an error and will not allow you to access the link properties, and hence you will not be able to edit the target location.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .