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

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


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.


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