有个需求,有一堆源码,需要给这些代码写cmake文件,就需要将c++中的两种后缀文件分离出来。
采用python进行处理:
# -*- coding: utf-8 -*-
import os
def listdir(path, list_name):
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
pass
elif os.path.splitext(file_path)[1]=='.cc':
name=os.path.split(file_path)
if name[1].find("test")==-1:
list_name.append(name[1])
file_name=[]
path="net/third_party/quiche/src/common"
listdir(path,file_name)
file_name.sort()
file_out="source.txt"
f_out=open(file_out,'w')
for i in range(len(file_name)):
f_out.write(path+"/"+file_name[i]+"\n")
f_out.close()