Python Forum

Full Version: pathlib:file in a directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have a reference to a pathlib.Path object that is a reference to a file system object that may not exist. also, i have a reference to a pathlib.Path object that is a reference to a directory that may not exist (in which case, by itself, it is not really known that it is a directory). i want to determine if that file system object is (or would be) in (at any level of depth) that directory. i could get strings of both, verify that the object path string begins with the whole directory string and has a '/' next (in my case, this is always Posix). but could there be ways a Path object can do this better (such as a Pythonic way or a portable way)?
Perhaps the PurePath.relative_to() method?