Search code examples
pythonsymlink

How to delete a symbolic link in python?


I have been trying to delete some symbolic links in my working directory, but I am facing some issues.

os.remove also removes the actual contents of the original folder of the link

os.shutil throws up an error in case of symbolic links.

Is there a way to remove a symbolic link using python commands without destroying the original content?

Thanks


Solution

  • os.unlink() works for me. It removes the symlink without removing the directory that it links to.