[Tutor] Problems with for loops and information
Chris Davidson
cxd401@psu.edu
Sun Nov 3 13:29:02 2002
Hello Tutor List,
This is my first post, so if you see anything that I am not doing
proper in this post, don't be afraid to yell at me.
My question is on the basis of searching through a list of files and/or
directories from os.listdir()
The code I have right now is
import os
listDirectory = "/home/chris"
for element in listDirectory:
if os.path.isdir(element):
print "Directory: %s " % element
elif os.path.isfile(element):
print "File: %s " % element
That code will not get into the if/elif statement, my question is: Is
this because i am going to through it with a for loop and it changes the
data type to string and can't find out if it is a directory? or probably
what I am thinking it is. I am missing an important part to make this
work.
This is not the final code, i am just trying to get the for loop to work
so what I really want to do with the data will work.
Thank you for your time everyone and thanks in advance for any help,
Chris