python获取文件夹的大小(即取出所有文件计算大小)

import os

path = r'/Users/authurchen/PycharmProjects/Demo'

# print(os.listdir(path))

ls = os.listdir(path)
files = [] def get_all_file(dir_path):
global files
for filepath in os.listdir(dir_path):
tmp_path = os.path.join(dir_path,filepath)
if os.path.isdir(tmp_path):
get_all_file(tmp_path)
else:
files.append(tmp_path)
return files def calc_files_size(files_path):
files_size = 0
for f in files_path:
files_size += os.path.getsize(f)
return files_size files = get_all_file(path)
print(calc_files_size(files))
上一篇:wxWidgets刚開始学习的人导引(3)——wxWidgets应用程序初体验


下一篇:LeetCode 题解之Linked List Cycle II