python实用一技--重命名
某宝给小朋友买了个电子琴学习光盘,想放到ipad播放,但光盘上的文件为dat格式,需转为msp格式,以下为转换代码(其实就是重命名文件):
#encoding=utf-8
"""
将VCD的DAT文件命令为mpg文件
"""
import os
path = r"E:\家庭&生产\B\MPEGAV2"
filelist = os.listdir(path)
count=0
def getNewName(oldfile): #旧名改新名
name = oldfile.split(‘.‘)[0]
return name + ".mpg"
for file in filelist:
# print(file)
if "DAT" in file:
newname = getNewName(file)
old_file = os.path.join(path, file)
new_file = os.path.join(path, newname)
print("rename %s to %s" %(old_file,new_file))
os.rename(old_file, new_file) #重命名核心功能函数
else:
print("not dat file") 相关推荐
heheeheh 2020-09-11
zhaomengsen 2020-06-09
zhouhaihua00 2020-05-05
liuyong00 2020-05-01
NSapientia 2020-01-21
zmosquito 2020-01-24
eroshn 2020-01-24
sansan 2020-01-04
ShoppingChen 2019-12-31
zmosquito 2019-12-12
airfling 2019-11-25
Yyqingmofeige 2019-10-25
yuhuijun 2014-04-16
思考zhe 2019-06-03
huhongfei 2016-05-31
linux爱好者 2019-06-03
Trisyp 2019-04-15