首先这个只能用递归的方式进行统计和计算,计算的数为全局变量

import os


def get_file_num(path):
    global num_total, file_num
    # path = r"E:\004_kongfuz_selenium70_120W"
    os.chdir(path)
    ret = os.listdir()
    # os.getcwd()
    print(ret)
    print(os.getcwd())
    current_path = os.getcwd()
    for i in ret:
        path1 = os.path.join(current_path,i)
        a = os.path.isdir(path1)
        if a:
            get_file_num(path1)
        else:
            file_num += 1
    num_total += len(ret)


if __name__ == '__main__':
    num_total = 0
    file_num = 0
    path = r"E:\004_kongfuz_selenium70_120W"
    get_file_num(path)
    print(num_total,file_num)