---
title: "介绍一个好用的代码统计工具"
author: "stamen"
date: "2014-09-27T20:24:44Z"
tags: []
categories: ["研发管理"]
slug: "untitled"
draft: false
lastmod: "2014-09-28T10:11:04Z"
id: 2123026
url: "https://stamen.iteye.com/blog/2123026"
---

想知道了解一下项目的代码规模，得到类数，代码行等统计信息，就用cloc吧，很好，很强大。 可以到这里详细了解一下。 \[url]http://cloc.sourceforge.net/\[/url] cloc支持几乎什么的OS并自动识别多种语言的代码(C++,Java,JavaScript,SQL,CSS等等)，当然也包括Windows，如果是Windows直接下载EXE文件（http://sourceforge.net/projects/cloc/），设置一个PATH环境变量就可以用了。 \[code="java"] &gt;cloc &lt;项目文件夹&gt; \[/code] 即可得到代码的统计信息： \[img]http://dl2.iteye.com/upload/attachment/0101/5681/18f62900-58d2-3ea9-be46-81d169419074.png\[/img] 也可以将统计信息写到一个文件中(支持不同格式) \[code="java"] cloc ridge --report-file=f:\\ridge.csv --csv \[/code] 以上命令，将ridge项目的代码统计信息写到一个csv格式的文件中。 如果希望将某些文件排除在外(如有些JS文件是第三方的,如JQuery等)，那么可以通过 \[quote]--exclude-list-file= Ignore files and/or directories whose names appear in . should have one entry per line. Relative path names will be resolved starting from the directory where cloc is invoked. See also --list-file.\[/quote] 选项排除之，在excludeFiles.txt中每一行对应一个在排除的文件： \[quote] jquery.js kendo.js ... \[/quote] \[code="java"] cloc ridge --exclude-list-file e:\\excludeFiles.txt \[/code] 一般情况下，这些第三方的JS应该放到一个统一的目录下，如js/lib,这时可以通过 \[quote]--exclude-dir=\[,D2,]\[/quote] 以下命令，将lib文件夹下的所有文件排除，统计报告生成到一个csv中： \[code="java"] cloc . --exclude-dir=lib --csv --report-file=e:\\euler.csv \[/code] cloc的帮助信息很丰富，可以通过： \[code="java"]cloc --help\[/code] 查看之。