软著这东西有点奇葩,不能多说。
参考其它的博客,增加了源代码文件编码格式的设置,可自己增加要统计的代码格式,在 typeList 的中括号里增加就行了。
import os
projectDir='C:\\Users\\Administrator\\Desktop\\1\\myproject'
typeList = ['java'] #统计的源代码文件格式
fileCode = 'UTF-8' #源代码文件的编码格式
def getFileList(projectDir):
fileList = []
for parent,dirNames,fileNames in os.walk(projectDir):
for filename in fileNames:
ext = filename.split('.')[-1]
if ext in typeList:
fileList.append(os.path.join(parent,filename))
return fileList
def countLine(fileName, fileCode):
count = 0
for file_line in open(fileName,'r',encoding=fileCode).readlines():
if file_line != '' and file_line != '\n':
count += 1
print (fileName + '----' , count)
return count
if __name__ == '__main__' :
fileList = getFileList(projectDir)
totalCnt = 0
for sourcefile in fileList:
totalCnt = totalCnt + countLine(sourcefile, fileCode)
print ('Total Lines:',totalCnt)
下一步自动生产软著申请的源代码文档,即前3000行代码和后3000行代码。