1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| import os
def count_and_print(path, level=0, printable=True, threshold=0): count = 0 files = os.listdir(path) for i in files: file = os.path.join(path, i) if os.path.isfile(file): if i.startswith("._"): os.remove(file) count += 1 print(file) elif os.path.isdir(file): count += count_and_print(file, level+1, printable=printable, threshold=threshold) if printable and count > threshold: print('\t' * (level + 1) + path + '\t' + str(count)) return count
|