发布时间:2019-09-07 08:10:53编辑:auto阅读(1959)
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import os
# 第一种方法
files = os.listdir('.')
i = 1
for f in files:
filename, extname = os.path.splitext(f)
if extname == '.txt':
os.rename(f, 't%d%s' % (i, extname))
i += 1
print '#' * 30
#第二种方法,修改文件扩展名
for f in files:
file_name, file_extname = f.split('.')
# print file_name, file_extname
if file_extname == 'txt':
os.rename(f, '%s.py' % file_name)
print u'文件扩展名修改成功!'
上一篇: Python 学习笔记 (6)—— 读写
下一篇: python之文件操作、OS模块、CSV
51109
50502
41117
37965
32433
29333
28205
23049
23016
21339
1375°
2074°
1725°
1655°
1943°
1728°
2398°
4052°
3936°
2806°