手机
当前位置:查字典教程网 >脚本专栏 >python >python使用os模块的os.walk遍历文件夹示例
python使用os模块的os.walk遍历文件夹示例
摘要:复制代码代码如下:#-*-coding:utf-8-*-importosif__name__=='__main__':try:'''trav...

复制代码 代码如下:

#-*- coding:utf-8 -*-

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)

【python使用os模块的os.walk遍历文件夹示例】相关文章:

python调用shell的方法

python sys模块sys.path使用方法示例

python 合并文件的具体实例

python线程池的实现实例

python读写文件操作示例程序

Python读写Excel文件的实例

python切换hosts文件代码示例

python用ConfigObj读写配置文件的实现代码

python使用PyV8执行javascript代码示例分享

python模拟登陆Tom邮箱示例分享

精品推荐
分类导航