How do I get number of files in a particular directory.
Peter Otten
__peter__ at web.de
Fri Aug 13 06:09:57 EDT 2010
blur959 wrote:
> Hi, I tried that, but it doesn't seem to work. My file directory has
> many different files extensions, and I want it to return me a number
> based on the number of files with similar files extensions. But when I
> tried running it, I get many weird numbers. Below is my code i had so
> far and the result.
Use glob.glob() instead of os.listdir() if you are only interested in files
with a specific extension:
>>> import glob
>>> len(glob.glob("*.py"))
42
Peter
More information about the Python-list
mailing list