I created a symlink using mklink. Now I need to change it but I can't figure out how to delete it so I can recreate it correctly.


Be very careful.

If you have a symbolic link that is a directory (made with mklink /d) then using del will delete all of the files in the target directory (the directory that the link points to), rather than just the link.

SOLUTION: rmdir on the other hand will only delete the directory link, not what the link points to.

  • 97
    Having just accidentally done this (deleted the complete contents of the target folder), this an important tip. – Simon Gillbee Aug 8 '11 at 21:10
  • 4
    This answer is not entirely accurate. Del deletes files, not folders. Therefore, you would not use del to delete the link. – AMissico Mar 12 '13 at 1:47
  • 12
    But don't use rmdir in PowerShell. Wrap it in cmd first. See my answer below... – northben May 13 '13 at 21:25
  • 4
    How about if i delete it through windows explorer???? – Cheung Aug 11 '13 at 16:49
  • 6
    There Microsoft Employees go again, just trying to ruin my life, career, and Windows operating system. – ThorSummoner Aug 25 '14 at 7:52

To remove directory symbolic links created with mklink /d it is safe to just delete the symbolic link in explorer.

  • 23
    +1 for telling people it is save to delete symbolic link through Windows Explorer. – AMissico Mar 12 '13 at 1:45
  • 3
    It is correct. I do it all the time. Just tested it again right now. – ddelrio1986 Sep 29 '16 at 21:00
  • 2
    This just worked for me as well. i deleted the link not the source folder that was linked to. perhaps that the catch. – R Hughes Feb 24 '17 at 15:59
  • 3
    It is safe to just delete it with Rightclick -> Delete. This does NOT delete the linked folder. – 0x25b3 Sep 29 '17 at 13:24

For a symlink to a file, use del. For a symlink to a directory made with mklink /d, use rmdir.

  • 4
    Warning: "del" will delete the file and not just the link. – WoodenKitty Nov 12 '15 at 0:39
  • 6
    Warning from @Tristan is not correct, this answer is accurate. Tested on windows 7. – jiggunjer Jun 23 '16 at 3:07
  • 1
    In Windows 7 SP1 (64-bit), a symbolic link that points to either a file (e.g. created using MKLINK) or to a directory (MKLINK /D) can be deleted in Windows Explorer, using the ordinary Windows GUI 'delete' option, without deleting the target. Even a JUNCTION (e.g. created using the MKLINK /J command), if deleted in Explorer, will not delete the target directory nor its contents. If not empty, the target directory cannot even be deleted using the command DEL junction at the command prompt. Tested today. – Ed999 Jan 20 '17 at 15:56
  • On Windows Server 2012, this removed the directory contents that my symlink was pointed to... – C Bauer Jun 18 '18 at 14:12
  • You should warn people not to rmdir links from Powershell! – NH. Oct 29 '18 at 16:57

In Powershell, don't use rmdir! Use cmd /c rmdir .\Target instead. I tested this myself and confirmed it here: http://kristofmattei.be/2012/12/15/powershell-remove-item-and-symbolic-links/

  • That blog confuses the meaning of "Target", which is the actual directory the link points to, and which folks generally wish to avoid deleting whilst removing the link. – kreemoweet Sep 22 '15 at 16:59
  • rmdir is an internal command of cmd.exe, thus obviously to call it from other shells you'll need cmd /c or cmd /k. rmdir in PowerShell is just an alias to Remove-Item – phuclv Feb 7 at 0:17

There is another solution tested by me and safe to use. just add to the real folder _ (example: foo become foo_) then simply delete your symbolik link, then remove _ from your true folder.

  • 2
    yeah, this is 100% safest solution after you know that powershell does not give a s**t about rmdir – test30 Jul 3 '14 at 14:54
  • This is a clever precaution. +1 – Hanna Mar 4 '15 at 17:11
  • Warning: I don't think this MIGHT not work on Win10 since it's fixing shortcuts upon renaming. (At least classic Shortcuts) Not tested though. – 0x25b3 Sep 29 '17 at 13:26
  • I did this just in case. After I renamed the target folder, the symbolink link failed when I tried to access it, so I could delete it without worrying. – Andrew Apr 14 '18 at 0:39

mklink cannot be used to delete symbolic links. To remove a symbolic link, simply delete them as if you’re removing a normal file. For example, to delete the foo symbolic link created above, enter the following command:

If the link is a hard link to a directory:

C:\test>rmdir foo

or else, IF the link points to a file (as opposed to a dir)

C:\test>del foo

Source: http://www.mydigitallife.info/2007/05/22/create-symbolic-links-hard-links-and-directory-junctions-in-vista-with-mklink/

  • 2
    Just make sure you don't delete it with del /S or Explorer. – Hello71 Jul 24 '10 at 0:12
  • 1
    See eddyq's answer below because using del for a link made to a directory won't work and instead will attempt to delete teh contents of the folder. – jpierson May 7 '12 at 13:48
  • 2
    Hardlinks to directories don't exist. I think you meant to say symlink. – Brilliand Sep 8 '15 at 18:20

In my case (Windows 10), after creating the symbolic link using

MKLINK /D "C:\Users\username\Dropbox\MyProject" "C:\SourceProject"

and deleting via delete using the file explorer or keyboard delete key also deletes the original directory.

What you should do is to remove the link via command prompt.

C:\Users\username\Dropbox>rd /s MyProject

For details about the rd command: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rd

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.