Accessing File Path Components (Part 2)
Now another one is
.anchor. So you can inspect the
.anchor attribute of a
Path object, and that’s going to return the root directory. In this case, however, it returns actually a string. So this is not a
01:59 And most often you’ll see this behavior for directories where the name of a directory usually doesn’t contain a dot, and files often contain a dot with a file extension, but there’s also files that don’t have a file extension, so you would see the same behavior there.
The bottom line is that
Path objects don’t really distinguish between a file and a folder, and there only these two different methods,
.is_dir(), to figure out whether it’s a file or a directory.
Become a Member to join the conversation.