Share via


Remove symboliclink to a directory

Question

Friday, October 12, 2018 9:12 AM

Hi!

I've created a symbolic link to a directory with

New-Item -Path .\link -ItemType SymbolicLink -Value .\source

How do I remove the symbolic link but not the content from .\source?

All replies (6)

Monday, October 15, 2018 8:33 AM ✅Answered

Hi, 

According to my know, using del command line will delete all of the files in the target directory (the directory that the link points to), rather than just the link. On the other hand rmdir command will only delete the directory link, not what the link points to.

So try to use command line "rmdir path" to achieve your desire.

Bests, 

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Thursday, October 18, 2018 9:22 AM ✅Answered

Hi, 

Thank you for your quick reply. 

I am very glad the issue could be resolved at last. But I should apologize for my words which make you mistake the rmdir is a powershell command. In fact, the "rmdir" is comand prompt command line paramater, this command line is same as "rd" command. For more descirption about this command, please check /en-us/windows-server/administration/windows-commands/rd

If my reply is useful for you, please kindly mark it as an answer. It would help other customers to search for result more quickly.

Bests, 

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Saturday, October 13, 2018 9:15 PM

The Complete Guide to Creating Symbolic Links (aka Symlinks) on Windows does that help? :) its says;

'To get rid of a symbolic link, you can simply delete it like you would any other file or directory. Just be careful to delete the link itself rather than the file or directory it’s linking to.'

So I have a symlink on C:\Somewhere\data to E:\data. What it means do not delete E: the data! (or the symlink just stops working). It mean delete the 'folder' (symlink) on C:\Somewhere and that is all that deleted.

Been awhile since I deleted a symlink (did that booting the server off Linux Live as Windows refused to) and the data did remain, the system carried on working.

Belt and braces can you backup \ take a copy of that source if you have concerns? 


Wednesday, October 17, 2018 3:27 PM

Thanks

Very unfortunate that Powershell is not so symetrical yet.


Thursday, October 18, 2018 6:04 AM

Hi,

Do you mean you failed to remove symbolic link?

I would appreciate if you could capture a PowerShell screen shot with executed command and result. It is very useful for us to troubleshoot the issue and clear understand the error message. 

Bests, 

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Thursday, October 18, 2018 9:14 AM

I could remove it but not with PowerShell . I removed it with Command Prompt