How can I get the names of the files in a directory?

.removethis. "(.removethis.)kartic.krishnamurthy" at
Sat Jan 15 10:16:02 EST 2005

Sara Fwd said the following on 1/15/2005 8:10 AM:
> Can you guys also help me find a module that looks in
> a directory and print out the names of the files in there?

You can use glob:

 >>> import glob
 >>> from os.path import isfile
 >>> print filter(isfile, glob.glob('/tmp/*')) # can use patterns

(will print a list of all files in the given directory, matching the 
given pattern)

If you want to traverse a directory tree recursively, please take a look 
at this recipe:


More information about the Python-list mailing list