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

后端 未结 2 1951
余生分开走
余生分开走 2021-01-03 23:12

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)

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 23:37

    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.

提交回复
热议问题