最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python实现文件内容批量追加的方法示例
时间:2022-06-24 14:42:40 编辑:袖梨 来源:一聚教程网
#coding:utf-8
import os
#-------代码段一
#获取当前文件夹
filePath = os.getcwd()
#获取当前文件列表
fileNameList = os.listdir(filePath)
fileDirList = []
#获取文件路径列表
for fileName in fileNameList:
fileDirList.append(os.path.join(filePath, fileName))
#--------代码段二
f = open('code.txt', 'w')
f.write("开始写文件n")
f.close()
for code in fileDirList:
f = open('code.txt', 'a')
split = os.path.splitext(code)
if(split[1] == '.h' or split[1] == '.cpp'):
fz = open(code, 'r')
string = "源代码文件" + code +"代码:n"
f.write(string)
content = fz.read()
print "文件 %s 读写成功" % code
f.write(content)
fz.close()
f.close()
print "读写成功"
相关文章
- 团子出行app如何查看城际专线-城际专线入口在哪 05-26
- 千牛网页版-淘宝商家工作台官方登录入口 05-26
- 火车票余票怎么查-12306余票查询快捷入口 05-26
- 棕色尘埃2国际版wiki官网入口-2026棕色尘埃2国际版wiki官网 05-26
- 免费观影软件高速下载-海量电影免费在线观看 05-26
- 快手网页版在线观看网址入口-快手网页版在线观看高清入口 05-26