python使用os模块的os.walk遍历文件夹示例
作者:
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.walk函数查找windows文件方式
- Python文件遍历os.walk()与os.listdir()使用及说明
- Python os.listdir与os.walk实现获取路径详解
- python 中 os.walk() 函数详解
- 详解python os.walk()方法的使用
- Python使用os.listdir和os.walk获取文件路径
- Python使用os.listdir()和os.walk()获取文件路径与文件下所有目录的方法
- python 获取文件下所有文件或目录os.walk()的实例
- python使用os.listdir和os.walk获得文件的路径的方法
- Python中os.walk用法使用小结
