python筛选特定文件的信息按照格式输出到txt
最近搞数据库,为了把图片文件的信息导入数据库表中,我开始研究python列出图片文件,其中发现因为IE临时文件里有非常多的不需要的图片,就需要筛选掉一些文件。
最终用python输出了所有需要的图片文件的路径、文件名、时间到一个txt
import os
import time def IsObjfile( path , filename , suffix , shield ):
#判断文件是否以suffix中的串结尾以及是否有不需要的文件路径
flag1 = False
for tmp in suffix :
if filename.endswith( tmp ) :
flag1 = True
flag2 = True
for tmp in shield :
if tmp in path :
flag2 = False
return flag1 and flag2 def GetPicInfo( ObjPath , ObjFile ,suffix , shield ):
#查找文件输出到txt
f = open( ObjFile ,'w')
g = os.walk( ObjPath )
for path,d,filelist in g:
for filename in filelist:
tmpname = filename.lower()
if IsObjfile( path , tmpname , suffix , shield ) :
f.write( path + ',' )
f.write( filename + ',' )
timeStamp = os.stat( os.path.join( path , filename ) ).st_ctime
timeArray = time.localtime( timeStamp )
StyleTime = time.strftime( "%m %d %Y", timeArray )
f.write( StyleTime +',#\n')
f.close(); Path = 'G:'
File = 'picname.txt'
suffix = [ 'jpg' , 'png' , 'gif' ]
shield = [ '临时文件' , '办公' , 'SDL' ]
GetPicInfo( Path , File , suffix , shield )
python筛选特定文件的信息按照格式输出到txt的更多相关文章
- [转]SVN使用log,list,cat,diff查看所有及特定文件版本信息
[转]SVN使用log,list,cat,diff查看所有及特定文件版本信息 http://onefishum.blog.163.com/blog/static/5184730520113153402 ...
- Python 筛选前缀文件
筛选某一文件下内具备某一前缀的文件: for file in files filename = os.path.listdir(file) if 'qianzhui--' in filename: # ...
- input="file" 浏览时只显示指定excel文件,筛选特定文件类型
<p>显示 .xls, .xlsx, .csv 文件...</p> <input type="file" accept=".csv, app ...
- nput="file" 浏览时只显示指定excel文件,筛选特定文件类型
<p>显示 .xls, .xlsx, .csv 文件...</p><input type="file" accept=".csv, appl ...
- 手动加入PE文件数字签名信息及格式具体解释图之下(历史代码,贴出学习)
#include <windows.h> HANDLE hWriteFileHandle = NULL ; HANDLE hReadFileHandle = NULL ; HANDLE h ...
- 实现读入一个彩色视频文件并以灰度格式输出这个视频文件,学习opencv例2-10
#include "cv.h"#include "highgui.h"int main(int argc,char* argv[]){ //书本中的main没有 ...
- python 关于操作文件的相关模块(os,sys,shutil,subprocess,configparser)
一:os模块 os模块提供了许多允许你程序与操作系统直接交互的功能 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname&quo ...
- python关于操作文件的相关模块(os,sys,shutil,subprocess,configparser)
一:os模块 os模块提供了许多允许你程序与操作系统直接交互的功能 功能 说明 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirna ...
- 【转】Python处理wave文件
#本文PDF版下载 Python解析Wav文件并绘制波形的方法 #本文代码下载 Wav波形绘图代码 #本文实例音频文件night.wav下载 音频文件下载 (石进-夜的钢琴曲) 前言 在现在繁忙的生活 ...
随机推荐
- Uboot代码分析
(1)确定链接脚本文件:uboot根目录下Makefile中的LDSCRIPT宏值,就是指定链接脚本(如:arch/arm/cpu/u-boot.lds)路径用的.(2)从脚本文件找入口: 在链接脚本 ...
- QuickStart系列:docker部署之PostgreSQL
mysql --> mariadb --> postgresql 官网简介 https://www.postgresql.org/ 使用的镜像名称 centos/postgresql-96 ...
- bzoj2045
题解: 莫比乌斯反演经典题目 直接套公式好了 代码: #include<bits/stdc++.h> using namespace std; ; typedef long long ll ...
- python三目运算符
python 可通过 if 语句来实现三目运算符的功能,因此可以近似地把这种if语句当成三目运算符.作为三目运算符的 if 语句的语法格式如下: True_statements if expressi ...
- spring boot 发邮件
报错: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not con ...
- 基于.NET Core 框架搭建WebApi项目
一 什么是.NET Core? 随着2014年 Xamarin和微软发起.NET基金会,微软在2014年11月份开放.NET框架源代码.在.NET开源基金会的统一规划下诞生了.NET Core .也就 ...
- golang---map类型
map 类似其它语言中的哈希表或字典,以key-value形式存储数据 key必须是支持==或!=比较运算的类型,不可以是函数.map或slice Map查找比线性搜索快很多,但比使用索引访问数据的类 ...
- wxPython的使用--类似画板的界面
# -*- coding: utf-8 -*-import wximport wx.lib.buttonsimport cPickleimport os class PaintWindow(wx.Wi ...
- 5-log4j2.xml配置文件各个节点详解
具体配置参考官网:http://logging.apache.org/log4j/2.x/manual/configuration.html 一.log.xml文件的大致结构 <?xml ver ...
- puppet确保程序运行
exec { 'keep-nginx-running' : user => 'root', unless => 'ps -x | grep nginx|grep -v grep', com ...