import os
path
= 'E:\Qianfeng train\Qianfeng train code\project basics'
def GetSize(path
,size
=0):
FileList
= os
.listdir
(path
)
for file in FileList
:
newpath
= os
.path
.join
(path
,file)
if os
.path
.isdir
(newpath
):
size
+= GetSize
(newpath
)
else:
size
+= os
.path
.getsize
(newpath
)
return size
print(GetSize
(path
))
执行结果如下
205561
从文件属性中我们可以查看是否计算正确,如下图所示
转载请注明原文地址: https://win8.8miu.com/read-26744.html