当前位置:网站首页>Copy multiple Excel files and name them different
Copy multiple Excel files and name them different
2022-06-26 13:03:00 【All right, AP】
The code is as follows :
import os,shutil
import sys
result=[]
with open('name.txt','r',encoding='utf-8') as f:# A text list of names that need to be named
for line in f:
result.append(list(line.strip('\n').strip().split(',')))
print(result)
def copy_files(): # Define the function name
for i in result:
j=i[0]
for foldName, subfolders, filenames in os.walk(path): # use os.walk Method acquisition path Folder path under path , Subfolder name , All filenames
for filename in filenames: # Traverse all file names under the list
if filename.endswith('.xlsx'): # When the file name is .txt At the end of suffix
new_name=filename.replace('.xlsx','%s.xlsx'%(j)) # Give the file a new name
shutil.copyfile(os.path.join(foldName,filename), os.path.join(path2,new_name)) # Copy to new path , And rename the file
print(filename,"copied as",new_name) # Output hint
if __name__ == '__main__':
path = r'D:\ Desktop files \test2' # Before running the program , Remember to modify the home folder path !
path2 =r'D:\ Desktop files \test3' # New path for storing files , Do not put it under the original path , Otherwise, two more copies will be made
copy_files() # Call the defined function , Note that the name is consistent with the defined function name
边栏推荐
- 美学心得(第二百三十八集) 罗国正
- How does easygbs solve the abnormal use of intercom function?
- Tiger DAO VC产品正式上线,Seektiger生态的有力补充
- 源码学习:AtomicInteger类代码内部逻辑
- 使用SSH密钥对登陆服务器
- Research and development practice of Kwai real-time data warehouse support system
- [BSidesCF 2019]Kookie 1
- 倍福PLC旋切基本原理和应用例程
- NoSQL mongodb - 04 mongodb database and web service combination case
- 几行代码就能实现复杂的 Excel 导入导出,这个工具类真心强大!
猜你喜欢
随机推荐
Electron official docs series: Best Practices
Electron official docs series: Distribution
[极客大挑战 2019]RCE ME 1
C# 结构体:定义、示例
Research and development practice of Kwai real-time data warehouse support system
倍福PLC通过MC_ReadParameter读取NC轴的配置参数
goto语句实现关机小程序
【网络是怎么连接的】第二章(中):一个网络包的发出
倍福通过CTU和TON实现时间片大小和数量的控制
软件测试 - 概念篇
【网络是怎么连接的】第一章:浏览器生成消息
BigInt:处理大数字(任意长度的整数)
OPLG: 新一代云原生可观测最佳实践
ES6模块
KVM video card transparent transmission -- the road of building a dream
Less than 40 lines of code to create a blocprovider
轻流完成与「DaoCloud Enterprise 云原生应用云平台」兼容性认证
倍福Ethercat模块网络诊断和硬件排查的基本方法
PostGIS geographic function
软件测试 - 基础篇








