Count number of files with certain extension in Python

Something has to iterate over all files in the directory, and look at every single file name – whether that’s your code or a library routine. So no matter what the specific solution, they will all have roughly the same cost.

If you think it’s too much code, and if you don’t actually need to search subdirectories recursively, you can use the glob module:

import glob
tifCounter = len(glob.glob1(myPath,"*.tif"))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)