删除mac里面._开头的文件 2020-09-06

2020-09-06  本文已影响0人  五道口的程序狐
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
上一篇下一篇

猜你喜欢

热点阅读