wav文件重命名

使用cooleditor对语音裁剪后,生成的新文件的文件名是中文括号的,无法在Linux下正确读取,需要重新对文件进行命名。

 

# -*- coding: utf-8 -*-
import os
import sys
import shutil
path = "D:\\weiyun\\CMD-COOK"
name = "cmd"
startNumber = "00001"
fileType = ".wav"
count = 0
filelist = os.listdir(path)
#print(filelist)
for file in filelist:
    oldF = os.path.join(path, file)
    FileName=oldF.split('\\')[3] #取文件
    File=FileName.split('(')[0].strip()#取文件编号
    FileNumber=FileName.split('(')[1]
    Num=str(int(FileNumber.split(')')[0]) - 1)
    if os.path.isfile(oldF) and os.path.splitext(oldF)[1] == fileType:
        newF= File + "_" +  Num.zfill(4) + ".wav" #对文件重命名,保留四位长度编号,自动补零
        newF = os.path.join(path, newF)
        print(newF)
        print(oldF)
        shutil.copyfile(oldF, newF)
        #os.rename(oldF, newF)
    else:
        continue
    count += 1
print("一共修改了"+str(count)+"个文件")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值