惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
博客园_首页
Jina AI
Jina AI
WordPress大学
WordPress大学
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
美团技术团队
IT之家
IT之家
爱范儿
爱范儿
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】

博客园 - Lunais

恢复 git stash drop 丢失的内容 Git技巧:彻底重置本地仓库与远程同步,同时保留Stash内容 信源编码和信道编码区别 Leetcode scanf 一组数据差值之和最大 5G 3gpp协议 eclipse调试配置 find查找 浮点类型(float、double)在内存中的存储 yield [基础函数]memset用法 python2处理表格文件按照规则多行输出(中文路径,print) linux系统objdump输出动态库.so文件和静态库.a中符号表 Linux C下的正则表达式 kill eclipse C语言之表达式运算整体提升 查找函数对比:findall,search,match Linux backtrace() git本地协同
python复制删除文件&修改目录&执行bat(wins)
Lunais · 2021-04-07 · via 博客园 - Lunais
 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文件
for dirs in os.listdir(path):
    if os.path.isdir(dirs):
        for file in os.listdir(path+'/'+dirs):
            fout = open(path + '/a.txt', 'ab+')
            fin = open(os.path.join(path + '/' + dirs,file), 'rb')
            fout.write(fin.read())
            fin.close()
            fout.flush()
            fout.close()

copy(src, dest)会将目标文件覆盖,write可以使用追加方式写入

for dirs in os.listdir(path):
# print dirs
if os.path.isdir(dirs):
# print dirs
for file in os.listdir(path+'/'+dirs):
fout = open(path + '/uda.xml', 'ab+')
fin = open(os.path.join(path + '/' + dirs,file), 'rb')
fout.write(fin.read())
fin.close()
fout.flush()
fout.close()
# shutil.copy(os.path.join(path + '/' + dirs,file), os.path.join(path, 'uda.xml'))