Skip to content Skip to sidebar Skip to footer

Count The Number Of Files With A Special Suffix In A Directory Using Python

It is possible to count the number of all files in a directory by: import os path = '/mnt/BIGDATA/' num_files = len([f for f in os.listdir(path) if os.path.isfile(os.path.join(p

Solution 1:

import os
path = '/mnt/BIGDATA/'
numberof_dotpdf_files=0
for file in os.listdir(path):
        if file.endswith(".pdf"):
            numberof_dotpdf_files=numberof_dotpdf_files+1

Post a Comment for "Count The Number Of Files With A Special Suffix In A Directory Using Python"