• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python使用os模块的os.walk遍历文件夹示例

python使用os模块的os.walk遍历文件夹示例

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python os创建文件夹,python os 打开文件夹,python 创建文件夹,python 遍历文件夹,python 删除文件夹等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

import os

if __name__ == '__main__':
    try:
    '''traval and list all files and all dirs'''
    for root, dirs, files in os.walk('D:' + os.sep + 'Python27'):
        print '-------------------directory < ' + root + ' > --------------------------'

        for d in dirs:
        print d
        for f in files:
        print f
    except OSError, e:
    print os.strerror(e.errno)
</div>

</div>

您可能想查找下面的文章:

  • Python 使用os.remove删除文件夹时报错的解决方法
  • Python 使用os.remove删除文件夹时报错的解决方法
  • python使用os模块的os.walk遍历文件夹示例

相关文章

  • 在Python中marshal对象序列化的相关知识
  • Python实现查找系统盘中需要找的字符
  • python实现中文转换url编码的方法
  • Python文件去除注释的方法
  • python 文件和路径操作函数小结
  • 一个基于flask的web应用诞生(1)
  • python使用mailbox打印电子邮件的方法
  • 用Python和MD5实现网站挂马检测程序
  • Python字符串替换实例分析
  • python保存字符串到文件的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python rsa 加密解密
    • Python将图片批量从png格式转换至WebP格式
    • Python中绑定与未绑定的类方法用法分析
    • Python基础之函数用法实例详解
    • python的id()函数介绍
    • Windows下用py2exe将Python程序打包成exe程序的教程
    • python threading模块操作多线程介绍
    • python动态网页批量爬取
    • 在Python的Django框架中用流响应生成CSV文件的教程
    • Python+Django在windows下的开发环境配置图解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有