import os base = '/tmp/fj-sdk/src' out = [] for root, dirs, files in os.walk(base): rel = os.path.relpath(root, base) depth = 0 if rel == '.' else rel.count(os.sep) + 1 if depth > 4: dirs[:] = [] continue for f in sorted(files): if f.endswith('.java') and 'generated' not in rel: out.append(os.path.join(rel, f)) print(len(out)) open('/tmp/fj-sdk/tree.txt', 'w').write('\n'.join(out) + '\n')