#!/usr/bin/env python
# coding:UTF-8


"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: 目录遍历.py
@time: 2018/9/6 16:53
"""

import os
def getAllFiles(path,filler='    ',spfiller=''):
    dirList = os.listdir(path)
    spfiller += filler
    print(spfiller)

    for dirname in dirList:
        curpath = os.path.join(path,dirname)
        if os.path.isdir(curpath):
            print(spfiller + dirname)
            getAllFiles(curpath,spfiller=spfiller)
        else:
            print(spfiller + dirname)


if __name__ == "__main__":
    getAllFiles(r'E:\学习')

 

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐