Why doesn't this work as expected?
Martin von Loewis
loewis at informatik.hu-berlin.de
Tue Jun 5 04:47:30 EDT 2001
David LeBlanc <whisper at oz.nospamnet> writes:
> I'm trying to build a directory walker, doing some work on each actual
> file found in each directory. However, when I run the below code snippet
> on a directory containing both sub-directories and files, it says that
> all are not dirs.
>
> What is not right?
You need to concatenate the file name to the path, or change the
working directory:
> def getDirs():
> print dircache.listdir("l:/languages/python")
>
> for dir in dircache.listdir("l:/languages/C"):
dir = "l:/languages/C/"+dir
> if os.path.isdir(dir):
> print dir, "is a dir"
> else:
> print dir, "is not a dir"
>
> getDirs()
Regards,
Martin
More information about the Python-list
mailing list