os.walk 查看目录大小
# 又学到了。。 def Test1(rootDir): tmp_lst = [] for root,dirs,file in os.walk(rootDir): for f in file: tmp_lst.append(root+os.sep+f) size = 0 for i in tmp_lst: size += os.stat(i).st_size return size r = Test1('d:\\test') print(r)
# 又学到了。。 def Test1(rootDir): tmp_lst = [] for root,dirs,file in os.walk(rootDir): for f in file: tmp_lst.append(root+os.sep+f) size = 0 for i in tmp_lst: size += os.stat(i).st_size return size r = Test1('d:\\test') print(r)