1 Star 0 Fork 14

kdp/csmall-mobile-repo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
countline.py 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
MingXu-CHN 提交于 2022-04-06 03:05 . 静态页面基本完成
#/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Wangj
import os
import time
import re
basedir = './'
filelists = []
# 指定想要统计的文件类型
whitelist = ['html', 'js', 'vue']
blacklist = [r'node_modules', r'dist', r'miniprogram_npm', r'assets', r'utils', r'libs']
#遍历文件, 递归遍历文件夹中的所有
def getFile(basedir):
global filelists
for parent,dirnames,filenames in os.walk(basedir):
for filename in filenames:
ext = filename.split('.')[-1]
in_blacklist = False
for blackstr in blacklist:
if re.search(blackstr, parent):
in_blacklist = True
break
#只统计指定的文件类型,略过一些log和cache文件
if in_blacklist:
break
if ext in whitelist:
filelists.append(os.path.join(parent,filename))
#统计一个文件的行数
def countLine(fname):
count = 0
for file_line in open(fname, encoding='utf-8').readlines():
if file_line.strip() != '' and file_line.strip() != '\n': #过滤掉空行
count += 1
print (fname + '----' , count)
return count
if __name__ == '__main__' :
startTime = time.clock()
getFile(basedir)
totalline = 0
for filelist in filelists:
totalline = totalline + countLine(filelist)
print ('total lines:',totalline)
print ('Done! Cost Time: %0.2f second' % (time.clock() - startTime))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kdpk/csmall-mobile-repo.git
git@gitee.com:kdpk/csmall-mobile-repo.git
kdpk
csmall-mobile-repo
csmall-mobile-repo
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385