Source From Here
Question
How do I extract the target path from a symbolic link?
HowTo
The problem with os.readlink() is it will only resolve 1 step of the link. We can have a situation where A links to another link B, and B link is dangling:
Now in Python, os.readlink() gives you the first target:
But in most situations I assume we are interested in the resolved path. So pathlib can help here:
How do I extract the target path from a symbolic link?
HowTo
The problem with os.readlink() is it will only resolve 1 step of the link. We can have a situation where A links to another link B, and B link is dangling:
Now in Python, os.readlink() gives you the first target:
But in most situations I assume we are interested in the resolved path. So pathlib can help here:
This message was edited 5 times. Last update was at 25/01/2022 20:27:24
沒有留言:
張貼留言