Python 3.12+osfunction
os.path.isjunction
os.path — existence and type checks
Check whether a path is a Windows junction (always False on other OSes; 3.12+).
Syntax
os.path.isjunction(path)
A junction is an NTFS mechanism similar to a symlink to a directory but needing no special privileges; some system folders are built this way. islink does not recognise it, so code walking a tree on Windows should check both functions or risk an endless loop. On other systems it always returns False, never an error.
Examples
import os
print(os.path.isjunction(os.__file__)) # → False
print(os.path.isjunction('нет-такого-пути')) # → False (несуществующий путь — не ошибка, просто False)
d = os.path.dirname(os.__file__)
print(os.path.isdir(d), os.path.islink(d), os.path.isjunction(d)) # → True False False (для junction на Windows было бы True False True)
print('junction' if os.path.isjunction(os.path.join(os.getcwd(), 'data_link')) else 'обычный путь') # → обычный путь (junction создаётся только на Windows: mklink /J)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy