JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

list folder structure

发布时间 2023-03-22 21:11:43作者: xiaoxuxli
import os

def 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))

Reference:
[1] https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python

    本栏目推荐文章
  • IDEA项目名称后面出现中括号,模块Modules的名子和文件夹名称不同,可以右键修改名称也可以在File->Project Structure 修改Modules的Name(快捷键ctrl+Shift+Alt+s)
  • python经典有序序列的list列表推导式
  • Arrays.asList生成不可变list
  • C#中的List<T>和Dictionary<TKey, TValue>的底层原理
  • mybatis向xml文件传递list参数
  • python基础之list、tuple、dict、set
  • 获取直播间的最新评论 - python 取两个list的差集
  • C# 将string转list,将list转string
  • 常用容器:动态数组array、列表list、队列 queue、map或字典、 集合、栈等等
  • C#中的几种list类型
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们