手机
当前位置:查字典教程网 >脚本专栏 >python >Python实现计算文件夹下.h和.cpp文件的总行数
Python实现计算文件夹下.h和.cpp文件的总行数
摘要:平时自己写了很多代码,但从没好好计算总共写了多少行,面试时被问起来,就傻了。。。闲来无事,写个python程序来统计下importos###...

平时自己写了很多代码,但从没好好计算总共写了多少行,面试时被问起来,就傻了。。。闲来无事,写个python程序来统计下

import os ################################################################################ def calcLine(baseDir): lineCount = 0 try: for fileName in os.listdir(baseDir): fullPath = baseDir + fileName if os.path.isdir(fullPath): lineCount += calcLine(fullPath + '') #递归读取所有文件 if os.path.splitext(fullPath)[1] in (".h", ".cpp"): file = open(fullPath) for eachLine in file.readline(): lineCount += 1 file.close() except Exception as e: print(e) return lineCount ################################################################################ if __name__ == "__main__": baseDir = "K:C++MFCBubbleDragon" lineCount = calcLine(baseDir) print(lineCount)

【Python实现计算文件夹下.h和.cpp文件的总行数】相关文章:

python 实现文件的递归拷贝实现代码

python2.7删除文件夹和删除文件代码实例

Python高级应用实例对比:高效计算大文件中的最长行的长度

Python删除指定目录下过期文件的2个脚本分享

Python实现扫描指定目录下的子目录及文件的方法

python使用paramiko模块实现ssh远程登陆上传文件并执行

python实现定制交互式命令行的方法

用python实现的去除win下文本文件头部BOM的代码

python实现的二叉树算法和kmp算法实例

Pyramid将models.py文件的内容分布到多个文件的方法

精品推荐
分类导航