How to delete the symlink along with the source directory
问题 I would like to delete the symlink along with the source directory. For example - ls -lrt testsymlink -> /user/temp/testdir I would like to remove both testsymlink and /user/temp/testdir . Consider that I know the only the symlink name. Any utility with python will do great. 回答1: You can use the result of os.path.realpath to detect and delete the symlink target. Example: import os # ./foo -> ./bar filepath = "./foo" if (os.path.realpath(filepath) != filepath): targetpath = os.path.realpath