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:
count+=1
print count
source: https://askubuntu.com/questions/779362/how-can-i-list-only-folders-with-no-sub-folders-in-given-path
Sweet.
I’m completely scripting illeterate.
Thanks.
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
Thanks again.
1 Like