How to separate directory list and file list?

Oliver Andrich oliver.andrich at gmail.com
Sun Oct 23 11:25:11 EDT 2005


Hi,

2005/10/23, Gonnasi <harddong at 21cn.net>:
> With
> >glob.glob("*")
>
> or
> >os.listdir(cwd)
>
> I can get a combined file list with directory list, but I just wanna a
> bare file list, no directory list. How to get it?

don't know if it is the best solution, but it looks nice. :)

path = "/home/test"
files = [fn for fn in os.listdir(path) if
os.path.isfile(os.path.join(path, fn))]

This gives you just the list of files in a given directory.

Best regards,
Oliver



--
Oliver Andrich <oliver.andrich at gmail.com> --- http://roughbook.de/



More information about the Python-list mailing list