xiaoxiaoniaoer 2020-01-29
某宝给小朋友买了个电子琴学习光盘,想放到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")