Sorting Directories from files in a os.listdir??
Scott David Daniels
Scott.Daniels at Acm.Org
Thu Apr 10 08:19:52 EDT 2008
Soren wrote:
> Hi,
>
> I'd like to read the filenames in a directory, but not the
> subdirectories, os.listdir() gives me everything... how do I separate
> the directory names from the filenames? Is there another way of doing
> this?
>
> Thanks!
import os
base, files, dirs = iter(os.walk(dirname)).next()
# now files is files and dirs is directories (and base == dirname)
More information about the Python-list
mailing list