python3 遍历文件

程序很简单,parent,dirnames,filenames分别表明当前目录下的文件夹数及文件数,然后通过os.wolk向深入遍历。

 

import os
import os.path

# this folder is custom
rootdir="G:\Download"
for parent,dirnames,filenames in os.walk(rootdir):
    #case 1:
    for dirname in dirnames:
        print("parent folder is:" + parent)
        print("dirname is:" + dirname)
    #case 2
    for filename in filenames:   
        print("parent folder is:" + parent)
        print("filename with full path:"+ os.path.join(parent,filename))

posted @ 2015-10-16 23:18  绿色的麦田  阅读(3785)  评论(0编辑  收藏  举报