当前位置:网站首页>复制多个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() #调用定义的函数,注意名称与定义的函数名一致
边栏推荐
- Nodejs framework express and KOA
- Several rare but useful JS techniques
- 7-2 数的三次方根
- 国标GB28181协议EasyGBS级联宇视平台,保活消息出现403该如何处理?
- 7-3 最低通行费
- ES6:Map
- 第十章 设置结构化日志记录(二)
- Comparison of latest mobile phone processors in 2020 (with mobile phone CPU ladder diagram)
- File remote synchronization and backup artifact Rsync
- 5+API,清除应用缓存
猜你喜欢
Adobe Acrobat prevents 30 security software from viewing PDF files or there are security risks

processing 函数translate(mouseX, mouseY)学习

Configuring Apache digest authentication

不到40行代码手撸一个BlocProvider

The El form item contains two inputs. Verify the two inputs

Processsing 鼠标交互 学习

Laravel subdomain accesses different routing files and different modules
![Vivado 错误代码 [DRC PDCN-2721] 解决](/img/de/ce1a72f072254ae227fdcb307641a2.png)
Vivado 错误代码 [DRC PDCN-2721] 解决

软件测试 - 基础篇

深入解析 MySQL binlog
随机推荐
Echart堆叠柱状图:色块之间添加白色间距效果设置
A must for programmers, an artifact utools that can improve your work efficiency n times
nvm安装教程
Redis learning - 04 persistence
Redis learning - 02 common data types, operation commands and expiration time
Summary of some application research cases of UAV Remote Sensing in forest monitoring
Tiger DAO VC产品正式上线,Seektiger生态的有力补充
Msvcr110 not found DLL, unable to continue code execution Solution for startup
机器学习笔记 - 时间序列的季节性
power designer - 自定义注释按钮
Laravel subdomain accesses different routing files and different modules
一个初级多线程服务器模型
深度解析当贝盒子B3、腾讯极光5S、小米盒子4S之间的区别
黑马笔记---常用API
国标GB28181协议EasyGBS视频平台TCP主动模式拉流异常情况修复
Php+laravel5.7 use Alibaba oss+ Alibaba media to process and upload image / video files
微信小程序测试点总结
中科软外包一面
[solved] laravel completes the scheduled job task (delayed distribution task) [execute a user-defined task at a specified time]
单例的常用创建和使用方式