# encoding=UTF-8
import os
"""
递归计算目录空间大小
"""
def disk_usage(path):
total = os.path.getsize(path)
if os.path.isdir(path):
for filename in os.listdir(path):
childpath = os.path.join(path, filename)
total += disk_usage(childpath)
print('{0:7<}'.format(total), path)
return total
if __name__ == '__main__':
print(disk_usage(r'D:\codepath'))
统计指定目录空间大小
最新推荐文章于 2022-08-28 09:39:56 发布