在python中列出目录树结构?

在python中列出目录树结构?,第1张

在python中列出目录树结构?

这是一个用于格式化函数

import osdef list_files(startpath):    for root, dirs, files in os.walk(startpath):        level = root.replace(startpath, '').count(os.sep)        indent = ' ' * 4 * (level)        print('{}{}/'.format(indent, os.path.basename(root)))        subindent = ' ' * 4 * (level + 1)        for f in files: print('{}{}'.format(subindent, f))


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/5664421.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存