directory listing
Fredrik Lundh
fredrik at pythonware.com
Fri Nov 11 17:17:37 EST 2005
Michael Konrad wrote:
> > for x in listing:
> > print x
> > if os.path.isdir(x):
> > dirs.append(x)
> >
>
> Did that and I was just getting a bunch of [ ].
if you printed "x" (the filename), that doesn't sound very likely.
maybe you printed some other variable? (like "dirs")
> > for x in listing:
> > x = os.path.join(directory, x)
> > if os.path.isdir(x):
> > dirs.append(x)
>
> OK. This works except each entry in dirs now includes the full path.
> Is there an unjoin? :)
use two variables:
for name in listing:
fullname = os.path.join(directory, name)
if os.path.isdir(fullname):
dirs.append(name)
</F>
More information about the Python-list
mailing list