1

So I noticed when running os.path.isdir() on the subdirectories of my root directory, that it returned False for any hidden/protected folders. Is there any reason for this, or is it a known bug? If not, is there any way to fix this?

For reference, below is the code I am running:

import os
for path in os.listdir("/"):
    print path, os.path.isdir(path)

EDIT: this is the output for the above code

.DocumentRevisions-V100 False
.file False
.fseventsd False
.Spotlight-V100 False
.Trashes False
.vol False
Applications True
bin False
cores False
dev False
Developer False
etc False
home False
installer.failurerequests False
Library True
net False
Network False
opt False
private False
sbin False
System False
tmp False
User Information False
Users False
usr False
var False
Volumes False
Raymond
  • 31
  • 7
  • Does it work for non-hidden directories? Can you post some sample output, perhaps? – David Z May 05 '16 at 09:12
  • so I put the output above, the output is identical if I use `os.path.isdir(os.path.realpath(path))`, which _should_ remove any symbolic directories, and as you can see, it does work for some non-hidden directories such as `library` and `applications`, however, there are non-hidden folders it returns false for as well (including for example, `users`) – Raymond May 05 '16 at 09:17

1 Answers1

3

Try adding the directory name to the front of the path.

import os
for path in os.listdir("/"):
    print path, os.path.isdir("/" + path)
cdarke
  • 42,728
  • 8
  • 80
  • 84