python实现目录大小计算(含子目录)

path=r"F:\\PYTHON\\day8\\ftp_server\\"#这里我直接写了固定地址,你可以自己输入
file_size = 0
def split_doc(path):
global file_size#声明全局变量
file_list=os.listdir(path)#将path下的所有目录列出(只列出path下的”儿子“目录,不含“孙子等”的目录)
for file in file_list:
#遍历文件及目录,如果是目录我再次调用该函数列出该目录下的所有文件和目录,否则计算文件大小的总和
if os.path.isdir(os.path.join(path,file)):
split_doc(os.path.join(path,file))
else:
file_size+=os.stat(os.path.join(path,file)).st_size
return file_size
print(split_doc(path))

  

上一篇:bugku 逆向 take the maze


下一篇:14.4.2 Change Buffer 延迟写