import os
from os.path import join, getsize
class one():
def panduan(self,a):
self.a = a
x=os.path.exists(self.a)
self.x = x
def shuju(self):
if self.x == True :
file_count = 0 #统计文件数量
for dirpath, dirnames, filenames in os.walk(self.a):
for f in filenames:
file_count = file_count + 1
self.count = file_count
size = 0 #统计文件夹大小
for root, dirs, files in os.walk(self.a):
size += sum([getsize(join(root, name)) for name in files])
self.daxiao = size
zwj = 0 #统计子文件夹数量
for file in os.listdir(self.a):
zwj += 1
self.zwj = zwj
else:
pass
def shuchu(self):
if self.x == True:
print('文件夹大小为:',self.daxiao)
print('文件数量为:', self.count)
print('子文件夹数量为:', self.zwj)
else:
print(self.a,'该路径不存在')
a = one()
b = input('请输入要统计的文件夹绝对路径:')
a.panduan(b)
a.shuju()
a.shuchu()