Python统计文件夹下各个子目录中的文件个数

import os
for dirpath, dirnames, filenames in os.walk("C:\\Users\\Administrator\\Desktop\\test_video_image"):
    file_count = 0
    for file in filenames:
        file_count = file_count + 1
    print(dirpath,file_count)

# #打印结果:
""""
C:\Users\Administrator\Desktop\test_video_image 0
C:\Users\Administrator\Desktop\test_video_image\frame_test 0
C:\Users\Administrator\Desktop\test_video_image\frame_test\aaa 38
C:\Users\Administrator\Desktop\test_video_image\frame_test\bbbb 3
C:\Users\Administrator\Desktop\test_video_image\frame_test1 19
C:\Users\Administrator\Desktop\test_video_image\video_test1 26
""""
posted @ 2020-01-11 10:01  lucky8492  阅读(2992)  评论(0编辑  收藏  举报