import os subDir = [] def listdirs(rootdir, count): def recurse(rootdir): nonlocal count for file in os.listdir(rootdir): d = os.path.join(rootdir, file) if os.path.isdir(d): recurse(d) count += 1 subDir.append(d) recurse(rootdir) print(f"Total directories are {count}") rootdir = ('/home/runner/TestP1') count = 0 listdirs(rootdir, count) print(subDir[2])
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)