Calculating number of end-folders

I have an archive with huge >5000 folders. with quite complex structure.
I would like to calculate number of end folders (not files) within given branch.
Windows options are giving me only total number of folders.
Anyone can help?

import os

count = 0
dir= ""
for root, dirs, files in os.walk(dir):
for dr in dirs:
    directory = root+"/"+dr
    if len([sub for sub in os.listdir(directory) \
            if os.path.isdir(directory+"/"+sub)]) == 0:
print count


I’m completely scripting illeterate. (4.1 KB)

I tried to do it exact way and I got an error in line 4 (some kind of exception).
Your script isn’t exact copy of the script from ‘ask ubuntu’ and I couldn’t change it myself.

17 246 is the number :slight_smile:
Thanks again.

1 Like