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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - 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'))