- #coding:utf-8
- import os
- #-------代碼段一
- #獲取當(dāng)前文件夾
- filePath = os.getcwd()
- #獲取當(dāng)前文件列表
- 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 "讀寫成功"
新聞熱點(diǎn)
疑難解答