os.walk(top, topdown=True, onerror=None, followlinks=False)
Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).
...
>>> import os
>>> rootdir = '/tmp/so'
>>> # print full path for first file in rootdir and for each subdir
... for topdir, dirs, files in os.walk(rootdir):
... firstfile = sorted(files)[0]
... print os.path.join(topdir, firstfile)
...
/tmp/so/a.txt
/tmp/so/users/a.txt
/tmp/so/users/sdb/a.txt
/tmp/so/users/sdb/case_23/d.txt
/tmp/so/users/sdb/case_23/scan_1/a.txt
os.walk
示例
dirs结构
dirs+文件结构
^{pr2}$python代码
相关问题 更多 >
编程相关推荐