重命名excel电子表格的文件夹python上的多个文件

时间:2021-10-03 20:26:01

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:

我是Python的新手,我想自动化一个过程,这需要花费我很多时间,但现在。我需要重命名大约需要重命名的200 + excel文件,但是这里有他们无法获得的结果,而是需要“查看”包含名称的主电子表格,然后将文件命名为其命名方式在主电子表格上。例如:

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.

基本上我只需要查看主电子表格的“FA ###”字符串,并根据主电子表格中的内容重命名该文件。

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

“资产运动215-156 6C”

And this is how it needs to look like exactly

这就是它需要的样子

146543115.NC251.LM5555989565C2-.215-156.NSD6C.556562443.MRO232324564612

1 个解决方案

#1


Something like this may help using pandas to deal with the Excel spreadsheet. I'm assuming 6C is relevant from the master spreadsheet.

这样的事情可能有助于使用pandas来处理Excel电子表格。我假设6C与主电子表格相关。

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)

#1


Something like this may help using pandas to deal with the Excel spreadsheet. I'm assuming 6C is relevant from the master spreadsheet.

这样的事情可能有助于使用pandas来处理Excel电子表格。我假设6C与主电子表格相关。

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)