Python修复图像文件后缀名
网上爬了很多图片,有很多错误。
有的不是图片文件,需要删除
有的后缀名错误,需要更正
用的的python脚本
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# fixImageExt.py
from PIL import Image
imoport os
import sys f = open(sys.argv[1]) # 文本文件,每一行是一个文件路径 for i, line in enumerate(f):
fullName = line.strip()
if not os.path.exists(fullName):
continue
try:
img = Image.open(fullName)
except: # remove broken image files
print "Broken: %d %s"%(i, fullName)
os.remove(fullName)
else:
newName = os.path.dirName(fullName) + str(i) + img.format.lower()
os.rename(fullName, newName)
print 'Rename ' + fullName + ' --> ' + newName
步骤:
1. 生成图片列表
find ImageDir -type f > images.txt
2. 运行脚本
python fixImageExt.py images.txt
Python修复图像文件后缀名的更多相关文章
- python分离不同后缀名的文件
功能描述 根据文件后缀名处理文件,分别拷贝到对应的文件夹下 example >>> .jpg 后缀 和.mp4 后缀文件处理 代码实现 #!/usr/bin/env python # ...
- python修改文件后缀名
修改文件后缀名 # -*- coding: utf-8 -*- import os # # 列出当前目录下所有的文件 # filedir = 'C:\\Users\\WT\\Desktop\\test ...
- python更改文件后缀名
path = '1024.png' extension = 'jpg' for i in range(1,len(path)): if (path[-i] == '.'):#找到后缀初始点 new_p ...
- pig脚本不需要后缀名(python tempfile模块生成pig脚本临时文件,执行)
pig 脚本运行不需要后缀名 pig脚本名为tempfile,无后缀名 用pig -f tempfile 可直接运行 另外,pig tempfile也可以直接运行 这样就可以用python临时文件存储 ...
- 如何批量修改文件后缀名,python来帮你
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取http ...
- python获取文件路径, 文件名, 后缀名
def get_filePath_fileName_fileExt(fileUrl): """ 获取文件路径, 文件名, 后缀名 :param fileUrl: :ret ...
- Python - 多次检查后缀名(endwith)
在通过后缀名查找类型文件的时候, 多次使用endwith, 使用元组(tuple), 简化操作. 此类方式, 也能够应用于if语句多次类似检測. 代码 # 列出目录内全部代码 def list_dic ...
- python应用-获取文件后缀名
def get_suffix(filename,has_dot=False): """ 获取文件后缀名 :param filename: 文件名 :param has_d ...
- 【日常小记】统计后缀名为.cc、.c、.h的文件数【转】
转自:http://www.cnblogs.com/skynet/archive/2011/03/29/1998970.html 在项目开发时,有时候想知道源码文件中有多少后缀名为.cc..c..h的 ...
随机推荐
- python的对象类型-----列表&元组&字典
列表: #定义列表 l=[1,'a',[3,4]] #l=list([1,'a',[3,4]]) #取值 print(l[0]) print(l[2][0]) l=[1,2,[['a','b'],'c ...
- git上面创建个人简历-链接
github创建个人在线简历: https://segmentfault.com/a/1190000006820290
- SpringBoot Maven打包项目JAR/WAR
安装Maven 1. 登录 http://maven.apache.org/download.cgi 2. 下载 maven 压缩包 3. 解压apache-maven-3.6.0-bin.tar.g ...
- ceph安装各种报错
[ceph_deploy][ERROR ] RuntimeError: Failed to execute command: ceph-disk-activate –mark-init sysvini ...
- mongodb count 导致不正确的数量(mongodb count 一个坑)
在mongodb 集群中,if 存在orphaned documents 和chunk migration, count查询可能会导致一个不正确的查询结果,例如我就是踩的这个坑,先不说话,看结果: ...
- JAVA基础补漏--字符串
字符串常量池 String a="abc"; String b="abc"; char[] str = {"a","b" ...
- springmvc异常处理(非注解与注解)
1.异常 程序中的异常一般分为两类:预期异常,运行时异常.前者是我们可预知的,我们一般通过捕获和抛出方式处理这些异常.后者主要通过代码规范.测试等手段来减少异常的发生.一般,我们在系统的DAO.Ser ...
- eclipse设置高亮显示的颜色
设置高亮显示的颜色:Window-->preferences-->General-->Editors-->Text Editors-->Annotations--> ...
- gzip: stdin: unexpected end of file tar: Unexpected EOF in archive
1.问题描述: 今天解压tar包遇到这样一个问题 使用命令:tar -zxvf xxxxx.tar.gz gzip: stdin: unexpected end of filetar: Unexpe ...
- Windows batch: call more than one command in a FOR loop?
https://stackoverflow.com/questions/2252979/windows-batch-call-more-than-one-command-in-a-for-loop U ...