首页 > 编程语言 > 详细

python--os模块递归本地目录

时间:2020-04-18 02:40:55      阅读:56      评论:0      收藏:0      [点我收藏+]
def getAllDirRE(path, sp = ""):
    #得到当前目录下所有的文件
    filesList = os.listdir(path)
    #处理每一个文件
    sp += "   "
    for fileName in filesList:
        #判断是否是路径(用绝对路径)
        fileAbsPath = os.path.join(path, fileName)
        if os.path.isdir(fileAbsPath):
            print(sp + "目录:", fileName)
            #递归调用
            getAllDirRE(fileAbsPath, sp)
        else:
            print(sp + "普通文件:", fileName)
# getAllDirRE("/data")

 

python--os模块递归本地目录

原文:https://www.cnblogs.com/lutt/p/12723314.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!