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:UsersAdministratorDesktop est_video_image 0 C:UsersAdministratorDesktop est_video_imageframe_test 0 C:UsersAdministratorDesktop est_video_imageframe_testaaa 38 C:UsersAdministratorDesktop est_video_imageframe_testbbb 3 C:UsersAdministratorDesktop est_video_imageframe_test1 19 C:UsersAdministratorDesktop est_video_imagevideo_test1 26 """"