Iterating all files in a directory
andy
andy at eastonwest.co.uk
Sun Jan 26 07:57:10 EST 2003
On Sunday 26 Jan 2003 1:20 am, Mongryong wrote:
> How can iterate through all the files in a directory?
>
> ie. obtain a list of all the file's name
>
> Thanks.
import os
for file in os.listdir("./"):
print file
Have a good look at the os module and its submodule path. Note that
os.listdir() returns a complete list of the files in the subdirectory, and
that no file specification is necessary, or allowed. Be aware that there may
be issues with the handling of unicode characters in filenames.
hope this helps
-andyj
More information about the Python-list
mailing list