python抓取文件夹的所有文件


Posted in Python onFebruary 27, 2018

本文实例为大家分享了python抓取文件夹的所有文件的具体代码,供大家参考,具体内容如下

#!/user/bin/python 
# -*- coding:utf8 -*- 
 
import Basic 
import os 
 
##################################################### 
########    Input      #### 
folder = "D:\\安装包" 
folder = folder.encode("gbk") 
 
########    Global      #### 
fileList = [] 
allFiles = [] 
tree = [] 
level = 0 
##################################################### 
 
try: 
 if folder is None or len(folder) == 0: 
  folder = os.curdir 
 
 if os.path.isdir(folder): 
  childFile = os.listdir(folder) 
  fileList = ["%s" % (folder+os.path.sep+f) for f in childFile] 
 
  node = {'file':folder, 'level':level} 
  tree.append(node) 
 
  while fileList is not None and len(fileList) > 0: 
   allFiles.append(""+fileList[0]) 
 
   if os.path.isdir(fileList[0]): 
    childFile = os.listdir(fileList[0]) 
 
    if childFile is not None and len(childFile) > 0: 
     fileList = fileList + ["%s" % (fileList[0]+os.path.sep+ft) for ft in childFile] 
    else: 
     pass 
   else: 
    pass 
 
   fileList.pop(0) 
 
  print "\n".join(["%s" % f for f in allFiles]) 
 else: 
  print 'not folder, no child' 
 
except Exception,x: 
 print x

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python实现根据ip地址反向查找主机名称的方法
Apr 29 Python
Python算术运算符实例详解
May 31 Python
Python列表list内建函数用法实例分析【insert、remove、index、pop等】
Jul 24 Python
python matplotlib绘图,修改坐标轴刻度为文字的实例
May 25 Python
python如何从文件读取数据及解析
Sep 19 Python
python3.7通过thrift操作hbase的示例代码
Jan 14 Python
Python中if有多个条件处理方法
Feb 26 Python
Python读写操作csv和excle文件代码实例
Mar 16 Python
python实现126邮箱发送邮件
May 20 Python
Python selenium爬取微信公众号文章代码详解
Aug 12 Python
Python 高效编程技巧分享
Sep 10 Python
Python爬虫爬取ts碎片视频+验证码登录功能
Feb 22 Python
python数据分析数据标准化及离散化详解
Feb 26 #Python
批量将ppt转换为pdf的Python代码 只要27行!
Feb 26 #Python
python 3利用Dlib 19.7实现摄像头人脸检测特征点标定
Feb 26 #Python
python3利用Dlib19.7实现人脸68个特征点标定
Feb 26 #Python
python微信跳一跳系列之棋子定位颜色识别
Feb 26 #Python
python微信跳一跳系列之棋子定位像素遍历
Feb 26 #Python
python3.6+opencv3.4实现鼠标交互查看图片像素
Feb 26 #Python
You might like
基于PHPExcel的常用方法总结
2013/06/13 PHP
解析centos中Apache、php、mysql 默认安装路径
2013/06/25 PHP
php curl基本操作详解
2013/07/23 PHP
ThinkPHP 3.2.3实现加减乘除图片验证码
2018/12/05 PHP
JS的递增/递减运算符和带操作的赋值运算符的等价式
2007/12/08 Javascript
JQuery扩展插件Validate 5添加自定义验证方法
2011/09/05 Javascript
js中页面的重新加载(当前页面/上级页面)及frame或iframe元素引用介绍
2013/01/24 Javascript
js中cookie的添加、取值、删除示例代码
2013/10/21 Javascript
node.js中的events.emitter.removeListener方法使用说明
2014/12/10 Javascript
js实现浮动在网页右侧的简洁QQ在线客服代码
2015/09/04 Javascript
JavaScript实现弹出模态窗体并接受传值的方法
2016/02/12 Javascript
JavaScript DOM节点操作实例小结(新建,删除HTML元素)
2017/01/19 Javascript
以BootStrap Tab为例写一个前端组件
2017/07/25 Javascript
解决vue打包项目后刷新404的问题
2018/03/06 Javascript
原生微信小程序开发中 redux 的使用详解
2021/02/18 Javascript
python根据时间生成mongodb的ObjectId的方法
2015/03/13 Python
python的exec、eval使用分析
2017/12/11 Python
PyQt+socket实现远程操作服务器的方法示例
2019/08/22 Python
python全局变量引用与修改过程解析
2020/01/07 Python
Python如何使用ElementTree解析xml
2020/10/12 Python
CSS3 重置iphone浏览器按钮input,select等表单元素的默认样式
2014/10/11 HTML / CSS
html5 viewport使用方法示例详解
2013/12/02 HTML / CSS
护理专业学生的求职信范文
2013/12/11 职场文书
2014年六一儿童节演讲稿
2014/05/23 职场文书
乡镇保密工作责任书
2014/07/28 职场文书
学校食堂标语
2014/10/06 职场文书
2015年医生个人工作总结
2015/04/25 职场文书
铁人观后感
2015/06/16 职场文书
Keras在mnist上的CNN实践,并且自定义loss函数曲线图操作
2021/05/25 Python
python生成可执行exe控制Microsip自动填写号码并拨打功能
2021/06/21 Python
python代码实现备忘录案例讲解
2021/07/26 Python
Python List remove()实例用法详解
2021/08/02 Python
使用Redis做预定库存缓存功能
2022/04/02 Redis
Python中time标准库的使用教程
2022/04/13 Python
Python读取和写入Excel数据
2022/04/20 Python
python实现双链表
2022/05/25 Python