1

In my dataset i have folders as follows :
['c7', 'c1', 'c4', 'c0', 'c6', 'c9', 'c8', 'c2', 'c5', 'c3']
i have found length of each folder using:

for i in os.listdir('../Project/Dataset/imgs/train'):
print(len(os.listdir('../Project/Dataset/imgs/train/'+i)))

I need to display each folder size with corresponding folder name

Ex: c7 : 2000 c3 : 2000

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
venkat0107
  • 240
  • 1
  • 12
  • [os.path.getsize](https://docs.python.org/3/library/os.path.html#os.path.getsize) – gavin Jul 16 '20 at 15:53
  • this thread should probably help you: https://stackoverflow.com/questions/2632205/how-to-count-the-number-of-files-in-a-directory-using-python – odyt3b Jul 16 '20 at 15:54

1 Answers1

1

If it is just about printing, then you can do the following:

import os
for i in os.listdir('../Project/Dataset/imgs/train'):
    num_files = len(os.listdir('../Project/Dataset/imgs/train/'+i))
    print("{} : {}".format(i, num_files))
spyralab
  • 161
  • 6