首页 > 编程语言 > 详细

python中os.walk浏览目录和文件

时间:2016-05-03 17:36:30      阅读:183      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python
# 2.py
# use UTF-8
# Python 3.3.0

# os.walk()的使用
import os

# 枚举dirPath目录下的所有文件

def main():
#begin
    fileDir = "F:" + os.sep + "aaa"        # 查找F:\aaa 目录下    
    for root, dirs, files in os.walk(fileDir):
    #begin
        print(root)
        print(dirs)
        print(files)
    #end
    os.system("pause")
#end

if __name__ == __main__:
#begin
    main()
#end


# 输出
# F:\aaa
# [‘4‘]
# [‘1.txt‘, ‘2.txt‘, ‘3.txt‘]
# F:\aaa\4
# []
# [‘5.txt‘, ‘6.txt‘, ‘7.txt‘]

 

python中os.walk浏览目录和文件

原文:http://www.cnblogs.com/heshangaichirou/p/5455465.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!