1 Star 0 Fork 0

nonzee/second_week_homework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1 614 Bytes
一键复制 编辑 原始数据 按行查看 历史
nonzee 提交于 2019-07-10 18:23 +08:00 . 更新 1
#作业1
#使用文件和目录操作,定义一个统计指定目录大小的函数(注意目录中还有子目录)
#导入模块
import os
count = 0 # 设置一个全局变量用来统计目录的大小
def count_file(file):
global count
dlist = os.listdir(file)
for f in dlist:
absfile = os.path.join(file, f)
if os.path.isfile(absfile):
count += os.path.getsize(absfile)
if os.path.isdir(absfile):
count_file(absfile)
if __name__ == "__main__":
count_file("./images")
print("该目录的大小为:", count)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nongee2014/second_week_homework.git
git@gitee.com:nongee2014/second_week_homework.git
nongee2014
second_week_homework
second_week_homework
master

搜索帮助