Lets say I have directories like:
foo/bar/
bar
is chmod 777
and foo
is 000.
When I call os.path.isdir('foo/bar')
it returns just False, without any Permission Denied Exception or anything, why is it like that? Shouldn't it return True?
If you are not root then you cannot access foo. Therefore you can't check if foo/bar exists and it returns False because it cannot find a directory with that name (as it cannot access the parent directory).
os.path.isdir
can return True
or False
, but cannot raise an exception.
So if the directory cannot be accessed (because parent directory doesn't have traversing rights), it returns False
.
If you want an exception, try using os.chdir
or os.listdir
that are designed to raise exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With