Count number of files with certain extension in Python

前端 未结 5 688
一整个雨季
一整个雨季 2020-12-12 23:55

I am fairly new to Python and I am trying to figure out the most efficient way to count the number of .TIF files in a particular sub-directory.

Doing some searching,

5条回答
  •  时光说笑
    2020-12-13 00:49

    Your code is fine.

    Yes, you're going to need to loop over those files to filter out the .tif files, but looping over a small in-memory array is negligible compared to the work of scanning the file directory to find these files in the first place, which you have to do anyway.

    I wouldn't worry about optimizing this code.

提交回复
热议问题