python读取文件名并改名字的实例
作者:黄晃晃亚亚 时间:2021-03-19 12:45:37
第一版,能实现,但最后发现文件的顺序改变了:
import os
def reename():
nm=1
pathh="/home/huangyaya/file/image/pic/chips"
filelist=os.listdir(pathh)
for files in filelist:
Olddir=os.path.join(pathh,files)
filename=os.path.splitext(files)[0]
filetype=os.path.splitext(files)[1]
Newdir=os.path.join(pathh,str(nm)+'.'+filetype)
os.rename(Olddir,Newdir)
nm+=1
reename()
新的
import os
import pdb
#dir_ = os.getcwd()
#dir_ += '/cips'
#os.chdir(dir_)
path_A = "/home/huangyaya/file/image/pic/wine"
path_B = "/home/huangyaya/file/image/pic/wine_output"
file_number = 1
num = 0
A_list = os.listdir(path_A)
B_list = os.listdir(path_B)
A_list_num = 0
B_list_num = 0
for A_str in A_list:
A_str_front = A_str[:-4]
B_str = A_str_front + '.xml'
os.rename(path_A + '/' + A_str,str(file_number) + '.jpg')
os.rename(path_B + '/' + A_str_front + '.xml',str(file_number) + '.xml')
file_number += 1
来源:https://blog.csdn.net/huangyaya27/article/details/79721156
标签:python,文件名
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PyCharm专业最新版2019.1安装步骤(含激活码)
2022-10-21 19:56:06
![](https://img.aspxhome.com/file/2023/7/89217_0s.png)
django云端留言板实例详解
2023-12-13 08:17:59
python算法深入理解风控中的KS原理
2021-01-12 21:27:37
![](https://img.aspxhome.com/file/2023/6/101566_0s.png)
matplotlib.subplot()画子图并共享y坐标轴的方法
2023-03-27 12:26:10
![](https://img.aspxhome.com/file/2023/4/96904_0s.png)
Django处理多用户类型的方法介绍
2022-11-30 10:16:54
![](https://img.aspxhome.com/file/2023/3/85033_0s.png)
TensorFlow卷积神经网络之使用训练好的模型识别猫狗图片
2023-09-07 03:34:41
![](https://img.aspxhome.com/file/2023/8/106998_0s.png)
Python中使用Flask、MongoDB搭建简易图片服务器
2021-12-09 19:57:16
Python3读写ini配置文件的示例
2023-05-29 22:59:21
在Python中使用异步Socket编程性能测试
2023-04-20 23:19:56
Pandas提取单元格的值操作
2022-10-19 08:34:21
Python+ Flask实现Mock Server详情
2021-02-11 19:56:28
![](https://img.aspxhome.com/file/2023/0/67920_0s.png)
一场关于YUI3/jQuery的精彩辩论
2010-11-11 12:50:00
Django框架首页和登录页分离操作示例
2022-10-06 02:16:42
![](https://img.aspxhome.com/file/2023/2/88892_0s.png)
Python3监控疫情的完整代码
2023-09-24 09:53:19
![](https://img.aspxhome.com/file/2023/2/83782_0s.jpg)
Python语音识别API实现文字转语音的几种方法
2023-02-17 01:17:00
PHP函数原理理解详谈
2023-06-04 01:56:59
![](https://img.aspxhome.com/file/2023/0/55360_0s.png)
解析PHP中VC6 X86和VC9 X86的区别及 Non Thread Safe的意思
2023-11-06 13:11:37
Javascript 利用 DOM 特性的两个小技巧
2009-02-28 14:07:00
使用Python机器学习降低静态日志噪声
2021-11-09 23:48:57
![](https://img.aspxhome.com/file/2023/0/81520_0s.png)
Python创建增量目录的代码实例
2021-12-07 04:12:55
![](https://img.aspxhome.com/file/2023/6/105366_0s.png)