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
The rm command is the dedicated tool for deleting files and directories from the system. Because the symlink itself is a file, we can use the rm command to remove it. The following rm command will remove the symlink. To remove multiple symlinks, use rm as you would to remove multiple files.
remove() method in Python is used to remove or delete a file path. This method can not remove or delete a directory. If the specified path is a directory then OSError will be raised by the method.
To delete a symbolic link, treat it like any other directory or file. If you created a symbolic link using the command shown above, move to the root directory since it is "\Docs" and use the rmdir command. If you created a symbolic link (<SYMLINK>) of a file, to delete a symbolic link use the del command.
os.unlink()
works for me. It removes the symlink without removing the directory that it links to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With