日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

python批量修改文件名为excel中指定名称_在Python脚本的帮助下,使用excelsh中的名称映射重命名文件夹中的文件名...

發(fā)布時(shí)間:2025/3/15 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python批量修改文件名为excel中指定名称_在Python脚本的帮助下,使用excelsh中的名称映射重命名文件夹中的文件名... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在一個(gè)文件夾中有許多CSV文件我想重命名。有一個(gè)excel工作表,其中包含要重命名為文件夾的文件名。在

文件夾中的文件名為

測試數(shù)據(jù)?30四月.csv在

測試數(shù)據(jù)?20四月.csv在

測試數(shù)據(jù)18四月.csv等等

而excel工作表包含的名稱為

0.25-測試數(shù)據(jù)4月30日

0.98-4月20日測試數(shù)據(jù)

0.33-4月20日測試數(shù)據(jù)等

我的目標(biāo)是改名

“測試數(shù)據(jù)\u 30四月.csv“至”0.25-TestData_30四月.csv“其他文件也一樣。在

這是我寫的代碼(它不能按預(yù)期工作)import os

import xlrd

#Excel Sheet containing name of files to be renamed in that folder

path="C:\\Users\\Desktop\\Test_Data\\Test_Summary.xlsx"

#Folder Containg all orginal file names

dir = "C:\\Users\\Desktop\\Wear_Data"

wb = xlrd.open_workbook(path)

sheet = wb.sheet_by_index(0)

sheet.cell_value(0, 0)

#In excel sheet column X or col_values(23) contains the file name to be renamed

print(sheet.col_values(23))

list_of_filename_in_folder = [] # name of the files in the folder

list_of_filename_in_excel = [] #name of the files in excel

path_to_folder = '' # base path of folder

for name in list_of_filename_in_excel:

excel_file_name = os.path.join(path_to_folder, name,'.csv')

dir_file_name = os.path.join(path_to_folder,name.split('-')[1],'.csv' )

if os.path.exists(dir_file_name):

print('changing file name {} to {}'.format(name.split('-')[1],name))

os.rename(dir_file_name, excel_file_name)

else:

print('no file {} with name found in location'.format(name.split('-')[1]+'.csv')

總結(jié)

以上是生活随笔為你收集整理的python批量修改文件名为excel中指定名称_在Python脚本的帮助下,使用excelsh中的名称映射重命名文件夹中的文件名...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。