标签:int list sdi for while pre ret 循环 文件大小
递归:
def list_in(s):
result = 0
lst = os.listdir(s)
for i in lst:
i = s + "/" + i
if os.path.isfile(i):
result = result + os.path.getsize(i)
elif os.path.isdir(i):
ret = list_in(i)
result = result + ret
return result
print(list_in(r"G:/salar"))
循环:
lst = [r"G:/salar", ]
size_sum = 0
while lst :
l_lst = lst.pop()
list_name = os.listdir(l_lst)
for i in list_name:
ret = os.path.join(l_lst, i)
if os.path.isdir(ret):
lst.append(ret)
else:
size_sum += os.path.getsize(ret)
print(size_sum)
标签:int list sdi for while pre ret 循环 文件大小
原文地址:https://www.cnblogs.com/hadibingjing/p/12249808.html