filecount=0import osfor root,dir,files in os.walk("文件夹"): filecount+=len(files)print("文件夹下共有%d个文件"%filecount)
用os.walk遍历文件夹,计算文件的个数