博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[MTK FP]用Python把图片资源image.rar中为.pbm后缀的文件更改为.bmp后缀的方法
阅读量:4318 次
发布时间:2019-06-06

本文共 895 字,大约阅读时间需要 2 分钟。

    在MTK feature phone平台,MTK会把一些.bmp文件写成.pbm的后缀,对于开发者来说,因为.pbm的文件不能直接看效果,所以一般会手动重命名之后看效果。这样的更改方法,一个两个图片还可以,如果要批量查看,则会影响工作效率。

    这里介绍一种批量修改文件名后缀的方法。下面代码可以通过使用python中的os.walk方法实现一个目录中文件的遍历,并结合一些os函数实现批量文件的重命名。

 

#
 -*- coding: utf-8 -*-
#
 It is ok at python-3.3.1rc1.msi installer condition.
import os
import re
#
 change the following dir to your dir
walk_names = os.walk(r
'
F:\view\mtk_6250\plutommi\Customer\Images\FTE_SLIM320X480\MainLCD
')
for (directory, sub_directorys, file_names) 
in walk_names:
    
for name 
in file_names:
        m = re.match(r
'
(.+\.)pbm$
', name, re.I)
        
if m:
            src = os.path.join(directory, name)
            dst = os.path.join(directory, m.group(1)) + 
'
bmp
'
            
if 
not os.path.isfile(dst):
                os.rename(src, dst)
                
print(dst)
            
else:
                
print(
"
This file exist:
")
                
print(dst + 
'
\n
')

    上面代码中的print语句,是让开发者看到那些图片被重命名了,如果希望有更好的形式如写文件系统,自行修改也非常简单。

转载于:https://www.cnblogs.com/landlitao/archive/2013/04/01/3012970.html

你可能感兴趣的文章
verilog 代码编写小记
查看>>
PyQT的安装和配置
查看>>
从 docker 到 runC
查看>>
守护进程
查看>>
php数组
查看>>
Linux 防火墙
查看>>
互联网金融P2P主业务场景自动化测试
查看>>
array_filter函数的应用
查看>>
html,body
查看>>
一个Brushes笔画应用ios源码完整版
查看>>
IOS 网络浅析-(七 JSON解析之三方JSONKit)
查看>>
image的srcset属性
查看>>
vs + Qt 环境下配置QCustomPlot编译不通过
查看>>
[C#-SQLite] SQLite一些奇怪的问题
查看>>
Map的遍历
查看>>
hibernate中cache二级缓存问题
查看>>
My third day of OpenCV
查看>>
Java并发计数器探秘
查看>>
特色博客
查看>>
[Python] RuntimeError: Invalid DISPLAY variable
查看>>