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文件
原文:https://www.cnblogs.com/Lunais/p/14628035.html