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

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值