Remove directories from os.listdir output
Fredrik Lundh
fredrik at pythonware.com
Sun Feb 18 06:47:27 EST 2001
Fernando RodrÃguez wrote:
> I need to filter out all the diretories of the list returned by
> os.listdir(). How can I tell if an entry of that list is a dir or a regular
> file? O:-)
os.path.isdir(filename)
os.path.isfile(filename)
e.g.
for file in os.listdir(mydir):
fullname = os.path.join(mydir, file)
if os.path.isfile(fullname):
...
Cheers /F
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list