python学习笔记:遍历目录

import os
import os.path

if __name__ =='__main__':
    
    root_dir='g:\\download'
    for root, dirs, files in os.walk(root_dir):
        for dir in dirs:
            print 'root=%s dir=%s' % (root,dir)
            #print 'root='+root+' dir='+dir
            
        for file in files:
            print 'root=%s file=%s' % (root,file)
            #print 'root='+root+' fie='+file

 

posted on 2013-05-21 17:01  回头多少个秋  阅读(144)  评论(0编辑  收藏  举报