首页 > 编程语言 > 详细

python复制删除文件

时间:2021-04-07 20:29:57      阅读:21      评论:0      收藏:0      [点我收藏+]
 1 # -*- coding: utf-8 -*-
 2 import os,shutil
 3 #设定文件路径
 4 path = D:\\lunais
 5 
 6 #对目录下的文件进行遍历
 7 for file in os.listdir(path):
 8     if os.path.isfile(os.path.join(path,file))==True:
 9         if file.endswith(.axf):
10             new_name1 = name1.axf
11             new_name2 = name1.axf
12             print change name , new_name1, new_name2, success
13             shutil.copy(os.path.join(path,file),os.path.join(path,new_name1))
14             shutil.copy(os.path.join(path,file),os.path.join(path,new_name2))
15         if file == name.elf:
16             new_name1 = name1.elf
17             new_name2 = name2.elf
18             print change name , new_name1, new_name2, success
19             shutil.copy(os.path.join(path,file),os.path.join(path,new_name1))
20             shutil.copy(os.path.join(path,file),os.path.join(path,new_name2))
21 
22 os.remove(path+\\name.axf)
23 os.remove(path+\\name.elf)
os.chdir(path) #修改目录为path
os.chdir(‘..\\‘) #获取当前目录的上一级目录
print os.getcwd() #获取当前目录
os.system(‘abc.bat‘) #执行bat文件

 

python复制删除文件

原文:https://www.cnblogs.com/Lunais/p/14628035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!