Python脚本之批量实现文件内容追加
2014-11-11 19:52
876 查看
#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 "读写成功"
相关文章推荐
- Python实现文件内容批量追加的方法示例
- Python脚本程序实现搜索文本文件内容
- Python脚本程序实现搜索文本文件内容
- Python 脚本 批量删除目录下文件的特定内容
- 利用Python脚本实现-----登陆新浪微博&批量下载收藏内容
- 登陆新浪微博&批量下载收藏内容[Python脚本实现]
- python和shell脚本实现查看大文件指定区域范围内的文件内容
- python实现搜索文本文件内容脚本
- python脚本实现文件的批量移动、复制,以及删除指定后缀
- Python脚本实现文件内容替换
- 【Python小工具】Python实现批量解析PDF文件提取内容并写入到Excel中
- Python 实现在对一个目录下所有文件,指定某一行之后添加内容(批处理脚本)
- 登陆新浪微博&批量下载收藏内容[Python脚本实现]
- python实现批量文件内容替换
- python写的批量操作远程主机脚本(命令执行,上传、下载文件)
- 批量替换文件名和内容的Python脚本
- Python open读写文件实现脚本
- CSDN博客专栏文章批量下载脚本[python实现]
- Python open读写文件实现脚本
- Python实现txt文件内容快速合并功能