so the goal is to find the folder in a directory tree that has the greatest number of files and the folder that uses the most disk space.
import os
path = 'C:\\animal'
highestsize = ''
mostfile = ''
totalsize = 0
totalfile = 0
for i in os.listdir(path):
if not os.path.isfile(path + '\\' + i):
count = 0
count_file = 0
for dirpath, subfolder, filenames in os.walk(path + '\\' + i):
for file in filenames:
count_file += 1
count += os.path.getsize(os.path.join(dirpath, file))
if count_file > totalfile:
totalfile = count_file
mostfile = i
if count > totalsize:
totalsize = count
highestsize = i
print(highestsize, str(totalsize) + ' Byte')
print(mostfile + ' have the most files: ' + str(totalfile))