通过os.path.walk方法递归遍历目录中所有文档
2012-07-31 10:20
447 查看
当路径含中文时会有问题,需要编码下 , 如:
os.path.walk(unicode('E:\\python\\根目录', 'utf8'), show, None)
# -*- coding:utf-8 -*-
#! /usr/bin/python
import os
#递归遍历E:\目录下所有文件
def show(arg, dirname, filenames):
print 'dirname:' + dirname
for f in filenames:
if os.path.isfile(dirname+'\\'+f):
print dirname + f
os.path.walk('E:\\', show, None)
os.path.walk(unicode('E:\\python\\根目录', 'utf8'), show, None)
# -*- coding:utf-8 -*-
#! /usr/bin/python
import os
#递归遍历E:\目录下所有文件
def show(arg, dirname, filenames):
print 'dirname:' + dirname
for f in filenames:
if os.path.isfile(dirname+'\\'+f):
print dirname + f
os.path.walk('E:\\', show, None)
相关文章推荐
- Python利用递归和walk()遍历目录文件的方法示例
- Python通过递归遍历出集合中所有元素的方法
- Python通过递归遍历出集合中所有元素的方法
- 递归的一些方法使用:深度遍历路径中的所有文件和目录,删除一个有文件的文件夹
- golang filepath.Walk遍历指定目录下的所有文件
- 遍历目录下的所有文件-os.walk
- Python os.walk() 方法遍历文件目录
- os.walk( )遍历指定目录下的所有文件
- python中os.walk()遍历目录中所有文件
- shell 递归遍历目录下的所有文件并统一改名的方法
- 面试题-程序题-Java递归实现遍历文件目录(所有文件夹和子文件)
- python获取父类的子类(遍历,递归),并循环执行所有子类的某一方法
- 遍历某目录下的所有文件的方法
- 递归 / 迭代两种方法实现查找指定目录下所有文件
- 使用Shell遍历目录及其子目录中的所有文件方法
- java递归遍历获取目录下所有文件
- python使用os.walk和os.path.join来遍历文件夹的文件(包括子文件夹下的文件)
- Python os.walk遍历出某路径下所有文件
- (实用篇)PHP不用递归遍历目录下所有文件的代码
- Python遍历目录中的所有文件的方法