在excel电子表格的文件夹python上重命名多个文件 [英] Renaming multiple files on a folder python of a excel spreadsheet
问题描述
所以例如:
文件夹我有:
1. filexxxxFA9261
2. filexxxxFA3040
3. filexxxxFA5251
在我的主电子表格中我得到: p>
1. FA9261.4586.56641.1212
2. FA3040.6589.65555.1516
3. FA5251.3562.65555。 5633
基本上我只需要查看主电子表格的FA ###字符串并重命名该文件根据主电子表格中的说明。
有人可以指向正确的方向吗?我一直在努力寻找到处,但大多数重命名是依次完成的,而不是单独的电子表格。
下面是一个关于它应该如下所示的一个确切的例子: / p>
这是最初命名的文件(它根据谁发送它而有所不同):
资产运动 215-156 6C
这是需要如何看起来像
146543115.NC251.LM5555989565C2 - 。 215-156 .NSD6C.556562443.MRO232324564612
这样的事情可能有助于使用 pandas
来处理Excel电子表格。我假设6C与主电子表格相关。
import pandas
import shutil
master = pandas.io.excel.read_excel('master.xlsc','sheet1')
for master in
key1 = r.split('。')[3]
key2 = r.split('。')[4] [ - 2:]
old ='资产运动%s%s'%(key1,key2)
new = r
shutil.move(旧,新)
I am pretty new at Python and I want to automate a process that takes a lot of my time but now. I need to rename about 200 + excel files that need to be renamed, but here is the catch they cant be consequential instead they need to be "vlooked up" of a master spreadsheet that contains the names and then name the files exactly how its named on the master spreadsheet. So for example:
folder I got:
1. filexxxxFA9261
2. filexxxxFA3040
3. filexxxxFA5251
and on my master spreadsheet I got:
1. FA9261.4586.56641.1212
2. FA3040.6589.65555.1516
3. FA5251.3562.65555.5633
basically I just need to vlookup the "FA###" string of the master spreadsheet and rename that file according to what says on the master spreadsheet.
Can someone point me in the right direction? I have been trying to look it up everywhere but most renaming is done sequentially and not of a spreadsheet individually.
Here is an exact example on how it should look like:
This is how the file it’s named initially (it varies depending on who sent it):
"ASSET MOVEMENT 215-156 6C"
And this is how it needs to look like exactly
146543115.NC251.LM5555989565C2-.215-156.NSD6C.556562443.MRO232324564612
Something like this may help using pandas
to deal with the Excel spreadsheet. I'm assuming 6C is relevant from the master spreadsheet.
import pandas
import shutil
master = pandas.io.excel.read_excel('master.xlsc', 'sheet1')
for r in master:
key1 = r.split('.')[3]
key2 = r.split('.')[4][-2:]
old = 'ASSET MOVEMENT %s %s' % (key1, key2)
new = r
shutil.move(old, new)
这篇关于在excel电子表格的文件夹python上重命名多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!