python 统计文件夹内有多少文件夹 和 文件夹内有多少子文件


# -*- coding:utf-8 -*-
import os
path = os.getcwd()   #获取当前路径
count = 0
count1 = 0
for root,dirs,files in os.walk(path):    #遍历统计
      for each in files:
             count += 1   #统计文件夹下文件个数
for file in os.listdir(path): #file 表示的是文件名
        count1 = count1+1
print('当前文件夹下所有文件夹和文件总数:',count)  # 获取当前文件夹下所有文件夹和文件总数
print('当前路径下文件夹数目:',count1)  # 获取当前路径下文件夹数目
print('当前文件夹下所有子文件包含文件数目:',count-count1)

原文地址:https://www.cnblogs.com/Tdazheng/p/13819465.html