如何用python统计一个路径下的文件总数

如题所述

import os
def totalfile(dir):
    count=0
    for file in os.listdir(dir):
        if os.path.isfile(os.path.join(dir,file)):
            count+=1
        elif os.path.isdir(os.path.join(dir,file)):
            count+=totalfile(os.path.join(dir,file))
    return count

温馨提示:答案为网友推荐,仅供参考
相似回答