Code works in current dir only?

Paxton Sanders pcsanders at
Fri Aug 15 23:47:14 CEST 2008

Does anyone know why the following code successfully labels (with [f|d|?]) 
entries in the current directory, but not in any other 
directory?  (All other directories' entries print [?].)

I'm using Python 2.5.1 on Cygwin.


import os

# collect all files and their paths
def collectinfo(path):
    files = os.listdir(path)
    for n in files:
        if os.path.isdir(n):
            print "[d]", n 
        elif os.path.isfile(n):
            print "[f]", n 
            print "[?]", n

# this works
if __name__ == "__main__":

# this does not work, always labels with [?]
#if __name__ == "__main__":
#    collectinfo("/")

Paxton Sanders
pcsanders at

More information about the Python-list mailing list