How to count number of files in directory using Python

Counting number of files using python in specific folder can be done using multiple ways.  Some of these are mentioned below

https://gist.github.com/conquistadorjd/e7f4d592b518a664189e1fb14ad23331#file-file_count_in_directory-py

Here is the output

*** Program Started ***
Number of Files using os.walk : 7
Number of Files using listdir method#1 : 8
Number of Files using listdir method#2 : 7
Number of Files using listdir method#3 : 7
Number of Files using glob : 7
*** Program Completed ***

As you can see Number of Files using listdir method#1 are different, this is because, its counting a folder as a file.

 

CategoriesUncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *