[Tutor] for loop problems
Chris Davidson
cxd401@psu.edu
Mon Nov 4 14:21:00 2002
Hey everyone,
I took everyone's though into consideration and I have come up
with all
the changes, but now when i run the script I get very wierd output which
I do not understand.
This function is going to be used in a script that will get
directory
listing and format a webpage with the results for a real cheap web
browser interface to a filesystem. The reason for wanting '/' at the end
is for the end user to tell the difference easily between a directory
and a file.
If i input my ouput is:
Directories: Directories:
Documents D/o/c/u/m/e/n/t/s
LimeWire L/i/m/e/W/i/r/e
gaim g/a/i/m
Files that are passed through have no problem and detect them properly.
Here is the new function
def checkDirectories(directory):
endingMark = '/'
newList = []
for element in os.listdir(directory):
pathname = os.path.join(directory, element)
mode = os.stat(pathname)[ST_MODE]
if element.startswith('.'):
continue
if S_ISDIR(mode):
s = endingMark.join(element)
newList.append(s)
print s
elif S_ISREG(mode):
newList.append(element)
print "File: %s" % element
return newList
Thank you everyone for your help, this is a very resourceful mailing
list and I hope in the near future I will be able to payback for the
help you have given me.
Thanks,
Chris