如果文件是链接文件,如何找到链接的目标路径 [英] how to find target path of link if the file is a link file
本文介绍了如果文件是链接文件,如何找到链接的目标路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何查找文件是否为链接文件,并找到目标文件的路径(链接文件指向的实际文件)
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)
推荐答案
os.path .islink
(这是一个链接?)和 os.path.realpath
(最终指向路径,无论是否为链接)。
os.path.islink
(is it a link?) and os.path.realpath
(get ultimate pointed to path, regardless of whether it's a link).
如果 os.path.islink
为True,并且您只想关注第一个链接,请使用 os.readlink
。
If os.path.islink
is True, and you only want to follow the first link, use os.readlink
.
这篇关于如果文件是链接文件,如何找到链接的目标路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文