我是靠谱客的博主 迷路水杯,这篇文章主要介绍python使用os模块的os.walk遍历文件夹示例,现在分享给大家,希望可以做个参考。

复制代码 代码如下:

#-*- coding:utf-8 -*-

import os

if __name__ == '__main__':
    try:
    '''traval and list all files and all dirs'''
    for root, dirs, files in os.walk('D:' + os.sep + 'Python27'):
        print '-------------------directory < ' + root + ' > --------------------------'

        for d in dirs:
        print d
        for f in files:
        print f
    except OSError, e:
    print os.strerror(e.errno)

最后

以上就是迷路水杯最近收集整理的关于python使用os模块的os.walk遍历文件夹示例的全部内容,更多相关python使用os模块内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(311)

评论列表共有 0 条评论

立即
投稿
返回
顶部