为了账号安全,请及时绑定邮箱和手机立即绑定

Python文件路径和大小

Python文件路径和大小

一只名叫tom的猫 2021-03-20 11:08:40
我一直在尝试列出目录及其子目录中的所有文件,其路径及其在python中的大小。不知何故,仅显示其目录中的文件,而不显示子目录中的文件。import osfrom os.path import join, getsize,abspath, isfilefo=open("Size Listing.txt","a")def size_list(mypath):f = []for (dirpath, dirname, filenames) in os.walk(mypath):    f.extend(filenames)for i in f:    fo.write("\nPath: ")    fo.write(abspath(i))    fo.write(" Size: ")    fo.write(str(getsize(join(mypath,i))))    fo.write(" bytes")fo.close()有人可以帮我吗?也有人可以建议如何在Python中为文件路径和大小创建数据结构,因为我还需要进行一些排序。谢谢 :)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 155 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号