Reputation: 1213
Is it possible for a file f
that os.path.isfile(f)
and os.path.isdir(f)
both evaluate to false?
What would a third category be named in this case?
Szenario:
I have created a contentless file using touch
on ubuntu 18.04, which definitely is not a directory. Python (version 3.5) nevertheless returns false on isfile(f)
.
Edit: It turns out that the file indeed returned True, the earlier output was a small mistake in my code.
The question still remains as I thought about it this way:
I have a set (Set A) of all files in a directory.
I create a subset via isfile filtering (Set B).
I create a subsets via isdir filtering (Set C).
Would the union of B and C be equal to A?
Upvotes: 5
Views: 1851
Reputation: 561
Is it possible for a file f that os.path.isfile(f) and os.path.isdir(f) both evaluate to false?
yes .. if you ask for existence os.path.exists(f)
.
EDIT: to answer your more detalied question ..
Would the union of B and C be equal to A?
Normaly yes .. if you can assert that none of them is deleted in the meantime.
Take into account that dead links are not exists, which means that os.path.exists(deadlink)
of a (existing) link pointing to a dead end results in False
while os.path.islink(deadlink)
results in True
, no matter if it points to a existing object or a dead end.
Upvotes: 3