how to find target path of link if the file is a link file

橙三吉。 提交于 2019-12-18 18:50:05

问题


how to find if the file is a link file, and find the path of the target file (actual file pointed by the link file)


回答1:


os.path.islink (is it a link?) and os.path.realpath (get ultimate pointed to path, regardless of whether it's a link).

If os.path.islink is True, and you only want to follow the first link, use os.readlink.




回答2:


Use os.lstat(), then inspect the st_mode field.



来源:https://stackoverflow.com/questions/3212712/how-to-find-target-path-of-link-if-the-file-is-a-link-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!