当前位置:网站首页>Modify the video name from the name mapping relationship in the table

Modify the video name from the name mapping relationship in the table

2022-07-06 08:24:00 Don't seek great wealth, just seek wealth to rival the country

subject :
There is one voiceFile In the folder 50 The suffix is *.pcm The file name needs to be modified , The file suffix is reserved , Modified name reference :rename.csv The innuendo in , The first column is the original name of the document , The second column is the current name of the file , Every line has an innuendo ( First row of old names , The second column is the corresponding new name ), It is required to change the file name of the folder to B Column name

resolvent :

import os
import pandas as pd
from log_utils import Log_util
# csv File path 
csv_path=r"C:\Users\xdjiang6\Desktop\rename.csv"
#  Video folder path 
video_path=r"D:\xdjiang\voiceFile"
#  Read csv file 
res=pd.read_csv(csv_path)
#  The first column is the original name of the document ( Old name )
old_list=res.values[:,0]
#  The second column is the current name of the file ( Corresponding new name )
new_list=res.values[:,1]
#  Combine the read new name with the old name into a dictionary 
name_list=dict(zip(old_list,new_list))

#  Read all video files in the video folder 
aaa=os.listdir(video_path)

# Determine whether the video file name ==csv Extracted old file name , If equal , Change the video file name to the new file name 
for i in aaa:
    if i in name_list.keys():
        os.rename(os.path.join(video_path,i),os.path.join(video_path,name_list[i]))
        Log_util.mlog.debug(f"{
      i}:  The video name has been modified !")
    else:
        Log_util.mlog.error(f"{
      i}:  Not in the table , Please check !")
原网站

版权声明
本文为[Don't seek great wealth, just seek wealth to rival the country]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060819357367.html