python批量修改文件后缀示例代码分享
时间:2021-11-19 13:45:09
ipad的goodreader对JS文件支持不太好,虽然可以读取它但总是无法退出,回不了goodreader的主界面,因此我需要把js文件批量变成纯文本。基于这个目的,我搞了下面一个小应用:
# -*- coding:utf-8 -*-
import os
def rename():
path = raw_input("请输入要处理的文件夹路径")
print path
old_ext = "."+raw_input("请输入要处理的文件类型")
print old_ext
new_ext = "."+raw_input("请输入你想变成的文件类型")
print new_ext
for (path, dirs, files) in os.walk(path):#遍历目录树
for filename in files:
ext = os.path.splitext(filename)[1] #取得文件类型,注意它还带着点号
print ext;
if(ext == old_ext):
print "----------------"
newname = filename.replace(old_ext, new_ext)
oldpath = path + "\\" + filename
newpath = path + "\\" + newname
try:
os.rename(oldpath, newpath)
except BaseException, e:
print(str(e))
if __name__ == '__main__':
rename()
标签:批量修改文件后缀
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
为你总结一些php信息函数
2023-10-28 09:46:59
ASP如何输出字符
2007-09-22 18:41:00
python自动分箱,计算woe,iv的实例代码
2022-10-13 22:51:50
![](https://img.aspxhome.com/file/2023/3/88013_0s.jpg)
python爬虫容易学吗
2023-08-24 09:48:26
Python 在字符串中加入变量的实例讲解
2023-01-27 10:51:21
语义化的label?
2009-02-11 12:44:00
![](https://img.aspxhome.com/file/UploadPic/20092/11/mobileme-login-86s.jpg)
Python Trie树实现字典排序
2023-08-23 02:06:10
![](https://img.aspxhome.com/file/2023/3/61223_0s.jpg)
在keras下实现多个模型的融合方式
2023-06-03 17:14:59
![](https://img.aspxhome.com/file/2023/5/77755_0s.jpg)
python基础练习之几个简单的游戏
2023-06-27 14:22:18
如何判断字段的类型?
2010-01-18 20:48:00
FSO组件之文件操作(上)
2010-05-03 11:01:00
基于Python编写一个刷题练习系统
2022-10-01 13:28:34
![](https://img.aspxhome.com/file/2023/2/79442_0s.png)
如何自己制作验证码的head.fix和body.fix文件
2009-06-01 12:50:00
详解Python进阶之切片的误区与高级用法
2022-09-18 04:03:12
什么是Dynamic HTML(Dhtml)
2010-03-16 12:40:00
Python3.5面向对象编程图文与实例详解
2023-12-04 23:21:51
![](https://img.aspxhome.com/file/2023/8/88008_0s.png)
asp如何自动反馈电子邮件?
2002-01-01 06:54:00
python中os和sys模块的区别与常用方法总结
2022-05-26 18:04:24
Python 通过截图匹配原图中的位置(opencv)实例
2021-10-06 02:04:44
![](https://img.aspxhome.com/file/2023/4/63924_0s.jpg)
微信小程序按钮点击动画效果的实现
2023-08-26 03:22:21
![](https://img.aspxhome.com/file/2023/0/56230_0s.gif)