Getting all the *files* from a directory -- A better way??
scarblac at pino.selwerd.nl
Wed Mar 28 13:44:39 CEST 2001
Paul Jackson <pj at sgi.com> wrote in comp.lang.python:
> Close - better to use os.path.join (more portable across
> operating environments with different path component
> separator characters, such as '\' in DOS/Windows).
> files = filter(
> [os.path.join(dir, f) for f in os.listdir(dir)]
files = [os.path.join(dir, f) for f in os.listdir(dir)
If you do the map() with a list comprehension, why not the filter() as well.
I don't know if this is the Pythonic way to do it, but it comes pretty close
to the Haskellic way :).
More information about the Python-list