当前位置:网站首页>复制多个excel然后命名不同的名字
复制多个excel然后命名不同的名字
2022-06-26 12:37:00 【好了,ap】
代码如下:
import os,shutil
import sys
result=[]
with open('name.txt','r',encoding='utf-8') as f:#需要命名的名字的文本列表
for line in f:
result.append(list(line.strip('\n').strip().split(',')))
print(result)
def copy_files(): #定义函数名称
for i in result:
j=i[0]
for foldName, subfolders, filenames in os.walk(path): #用os.walk方法取得path路径下的文件夹路径,子文件夹名,所有文件名
for filename in filenames: #遍历列表下的所有文件名
if filename.endswith('.xlsx'): #当文件名以.txt后缀结尾时
new_name=filename.replace('.xlsx','%s.xlsx'%(j)) #为文件赋予新名字
shutil.copyfile(os.path.join(foldName,filename), os.path.join(path2,new_name)) #复制到新路径下,并重命名文件
print(filename,"copied as",new_name) #输出提示
if __name__ == '__main__':
path = r'D:\桌面文件\test2' #运行程序前,记得修改主文件夹路径!
path2 =r'D:\桌面文件\test3' #存放文件的新路径,不要放在原路径下,不然会多复制两份
copy_files() #调用定义的函数,注意名称与定义的函数名一致
边栏推荐
- 中科软外包一面
- PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
- "Pinduoduo and short video speed version", how can I roast!
- 软件测试 - 基础篇
- 国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
- 7-1 数的范围
- 轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证
- Tiger DAO VC产品正式上线,Seektiger生态的有力补充
- Processing 多面体变化
- [solved] data duplication or data loss after laravel paginate() paging
猜你喜欢
微信小程序测试点总结

老司机总结的12条 SQL 优化方案(非常实用)

PHP laravel+gatewayworker completes im instant messaging and file transfer (Chapter 1: basic configuration)

Laravel+gatewayworker completes the im instant messaging and file transfer functions (Chapter 4: server debugging errors)

PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)

Implementing mixins scheme in applet

Mysql8 master-slave replication

文件远程同步、备份神器rsync

dried food! Yiwen will show you SD card, TF card and SIM card!

国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
随机推荐
[solved] data duplication or data loss after laravel paginate() paging
Redis learning - 05 node JS client operation redis and pipeline pipeline
TP5 thinkphp5 extension package think Mongo operation mongodb time interval range query
sqlalchemy event listen Automatic generate CRUD excel
BigInt:处理大数字(任意长度的整数)
power designer - 自定义注释按钮
Ubuntu安装配置PostgreSQL(18.04)
美学心得(第二百三十八集) 罗国正
JS how to judge when data contains integer and floating-point types. Floating-point decimals retain two digits after the decimal point
栈,后入先出
Redis learning - 03 transaction
7-1 数的范围
Word文档导出(使用固定模板)
Less than 40 lines of code to create a blocprovider
Laravel subdomain accesses different routing files and different modules
Tiger DAO VC产品正式上线,Seektiger生态的有力补充
Xiaobai lazy special-win10-win11 one click installation version
ES6:迭代器
软件测试测试常见分类有哪些?
[BSidesCF 2019]Kookie 1