total number of files in a folder and subfolder python

Solutions on MaxInterview for total number of files in a folder and subfolder python by the best coders in the world

showing results for - "total number of files in a folder and subfolder python"
Fátima
09 Oct 2020
1import os
2
3APP_FOLDER = 'C:/Positronx/Python/Scripts/'
4
5totalFiles = 0
6totalDir = 0
7
8for base, dirs, files in os.walk(APP_FOLDER):
9    print('Searching in : ',base)
10    for directories in dirs:
11        totalDir += 1
12    for Files in files:
13        totalFiles += 1
14
15
16print('Total number of files',totalFiles)
17print('Total Number of directories',totalDir)
18print('Total:',(totalDir + totalFiles))