Getting all the *files* from a directory -- A better way??
Fredrik Lundh
fredrik at pythonware.com
Thu Mar 29 05:41:51 EST 2001
Alex Martelli wrote:
> So wrap it up...:
>
> def joined_listdir(dir):
> return [os.path.join(dir,f) for f in os.listdir(dir)]
or: glob.glob(os.path.join(dir, "*"))
> then use your wrapper:
>
> files1 = [f for f in joined_listdir(dir) if os.path.isfile(f)]
or: files1 = filter(os.path.isfile, joined_listdir(dir))
(shorter, faster -- and works for all versions of Python)
Cheers /F
More information about the Python-list
mailing list