【练习】用python写一个计算文件夹总大小的程序

import os
size=0
filename=‘输入你的文件夹绝对路径‘
for g in os.walk(filename):
path, dir_list, name_list=g
for name in name_list:
abs_path=os.path.join(path,name)
size+=os.path.getsize(abs_path)
print(‘文件总大小:%s‘%size)

相关推荐