How to delete a symbolic link in python?

akshayc11 picture akshayc11 · Jul 28, 2012 · Viewed 40.5k times · Source

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

Answer

samfrances picture samfrances · Jul 28, 2012

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