---
title: "代码统计工具COLC"
author: "fyting"
date: "2008-08-10T16:02:59Z"
tags: []
categories: ["Web前端"]
slug: "colc"
draft: false
lastmod: "2008-08-10T16:02:59Z"
id: 226339
url: "https://fyting.iteye.com/blog/226339"
---

虽说代码行数不重要，但有时候总想统计下自己的代码行数，看看最近的成果。以前一直用[这个](http://www.skycn.com/soft/7806.html)国产小软件，但感觉操作稍显烦琐，我更喜欢命令行的方式，自由度更高。昨天无意中在[这里](http://maomaode.bokeland.com/blog/3/187/2008/03/25/348806)发现了叫做CLOC的小软件，基于Perl，并且是Opensource的，地址是<http://cloc.sourceforge.net/>。下载后只有一个cloc.exe文件，使用方式也很简单，只需要：cloc.exe /path/to/source-code，输出如下:


```
C:\Documents and Settings\kenny>cloc D:\Projects\myproject\
     900 text files.
classified 900 files
     634 unique files.
     607 files ignored.

http://cloc.sourceforge.net v 1.04  T=3.0 s (84.3 files/s, 11367.0 lines/s)
-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
Java                135      1778      1963      8779 x   1.36 =       11939.44
Javascript           22      1875      1761      8590 x   1.48 =       12713.20
XML                  39       308       247      2744 x   1.90 =        5213.60
HTML                 39        33       474      2000 x   1.90 =        3800.00
CSS                  11       156        72      1445 x   1.00 =        1445.00
DTD                   1       234       254       713 x   1.90 =        1354.70
SQL                   2        42        44       406 x   2.29 =         929.74
JSP                   3        18        14       106 x   1.48 =         156.88
XSLT                  1         0         6        39 x   1.90 =          74.10
-------------------------------------------------------------------------------
SUM:                253      4444      4835     24822 x   1.52 =       37626.66
-------------------------------------------------------------------------------
```

当然了，有很多选项可以用，具体的可以看看cloc首页的介绍。当然，每次这样手动输入命令很麻烦，考虑下和Total-Commander结合。编辑一个cloc.bat文件，内容如下：

> cloc.exe %1
> PAUSE

把这个bat文件拖到TC的工具栏上
![](http://www.fyting.com/wp-content/uploads/2008/08/image-thumb.png)
然后在工具栏新出现的图标上点右键，选“更改”，然后把参数设置为%p，如图：
![](http://www.fyting.com/wp-content/uploads/2008/08/image-thumb1.png)
“确定”后大功告成，在TC里进入你的源码目录时，点击刚才新建的图标，就开始自动统计当前目录了。
下载地址: <http://sourceforge.net/project/showfiles.php?group_id=174787>