首页 > 编程语言 > 详细

python实用一技--重命名

时间:2020-01-29 20:33:04      阅读:67      评论:0      收藏:0      [点我收藏+]

某宝给小朋友买了个电子琴学习光盘,想放到ipad播放,但光盘上的文件为dat格式,需转为msp格式,以下为转换代码(其实就是重命名文件):

技术分享图片
 1 #encoding=utf-8
 2 """
 3  将VCD的DAT文件命令为mpg文件
 4 """
 5 import os
 6 path = r"E:\家庭&生产\B\MPEGAV2"
 7 filelist = os.listdir(path)  
 8 count=0
 9 def getNewName(oldfile):             #旧名改新名
10     name = oldfile.split(.)[0]
11     return name + ".mpg"
12 
13 for file in filelist:
14     # print(file)
15     if "DAT" in file:
16         newname = getNewName(file)
17         old_file = os.path.join(path, file)
18         new_file = os.path.join(path, newname)
19         print("rename %s to %s" %(old_file,new_file))
20         os.rename(old_file, new_file)        #重命名核心功能函数
21     else:
22         print("not dat file")
View Code

 

python实用一技--重命名

原文:https://www.cnblogs.com/cwind/p/12241100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!