Python遍历文件

来源:互联网 发布:成都管家婆软件 编辑:程序博客网 时间:2024/05/01 08:32

os.walk()返回一个三元素的tuple:当前路径、子文件夹名称、文件列表。

import osdef fun( path ):     for root, dirs, files in os.walk( path ):         for fn in files:             print root, fn
>>> fun( r'C:\TDDOWNLOAD' )C:\TDDOWNLOAD a.txtC:\TDDOWNLOAD b.txtC:\TDDOWNLOAD\sub1 c.txtC:\TDDOWNLOAD\sub1 d.txt
0 0
原创粉丝点击