使用walk来计算文件夹的总大小
import os g = os.walk('D:\python_22') size = 0 for i in g : path,dir_lst,name_lst = i for name in name_lst: abs_path = os.path.join(path,name) size += os.path.getsize(abs_path) print(size)
Dylan
import os g = os.walk('D:\python_22') size = 0 for i in g : path,dir_lst,name_lst = i for name in name_lst: abs_path = os.path.join(path,name) size += os.path.getsize(abs_path) print(size)