Creed Creed - 1 year ago 90
Python Question

os.path.isdir() not recognising hidden directories

So I noticed when running

on the subdirectories of my root directory, that it returned
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

Answer Source

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

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