资源简介

今天突然想统计一下代码的行数,没有想太多就动手写了一个。写完才发现是重复造轮子,网上已经有这样的工具了。既然造了,那就共相互来,能用得上的,就用用。 开发环境VS2012,.net 2.0 代码经过调整的,算是比较负责任。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.Regularexpressions;
using System.Diagnostics;

namespace SourceCodeAnalysis
{
    public partial class FrmLinesOfCodeStatistics : Form
    {
        public FrmLinesOfCodeStatistics()
        {
            InitializeComponent();
        }

        private void btnDoStatistics_Click(object sender EventArgs e)
        {
            if (!Directory.Exists(txtCodePath.Text))
            {
                MessageBox.Show(“请选择源文件夹路径“);
                return;
            }

            List codeFileCounterList =
                GetAllFilesStatistics(txtCodePath.Text cbSeacheSubFolder.Checked txtSourceFileExtension.Text cbNoEmptyLine.Checked txtOutOfStatistics.Text);

            FillToGrid(codeFileCounterList txtCodePath.Text);
        }

        private void FillToGrid(List codeFileCounterList string sourceFoloder)
        {
            dataGridView1.Rows.Clear();
            int totalEmptyLines = 0;
            int totalCustomExclusionLines = 0;
            int totalCodeLines = 0;
            int totalTotalLine = 0;
            foreach (var fileCounter in codeFileCounterList)
            {
                int rowid = dataGridView1.Rows.Add();
                DataGridViewRow row = dataGridView1.Rows[rowid];
                row.Cells[0].Value = fileCounter.FilePath.Replace(sourceFoloder ““);
                row.Cells[1].Value = fileCounter.BlankLine;
                row.Cells[2].Value = fileCounter.CustomExclusionLine;
                row.Cells[3].Value = fileCounter.CodeLine;
                row.Cells[4].Value = fileCounter.TotalLine;
                row.Tag = fileCounter;

                totalEmptyLines += fileCounter.BlankLine;
                totalCustomExclusionLines += fileCounter.CustomExclusionLine;
                totalCodeLines += fileCounter.CodeLine;
                totalTotalLine += fileCounter.TotalLine;
            }

            int totalRowId = dataGridView1.Rows.Add();
            DataGridViewRow totalRow = dataGridView1.Rows[totalRowId];
            totalRow.Cells[0].Value = “汇总:“;
            totalRow.Cells[1].Value = totalEmptyLines;
            totalRow.Cells[2].Value = totalCustomExclusionLines;
            totalRow.Cells[3].Value = totalCodeLines;
            totalRow.Cells[4].Value = totalTotalLine;
        }

        /// 
        /// 获取所有文件的统计信息
        /// 

        /// 源代码文件目录
        /// 是否获取子文件夹的文件。true,获取所有子文件夹的文件
        /// 要获取的文件的扩展名。多个扩展名用“|”分割,如:*.txt|*.cs 。 ““、“*““*.*“表示所有文件
        /// 不统计空行
        /// 用户定义的

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        896  2013-05-24 22:26  SourceCodeAnalysis.sln

     文件      19456  2013-05-27 00:36  SourceCodeAnalysis\bin\Debug\SourceCodeAnalysis.exe

     文件      38400  2013-05-27 00:36  SourceCodeAnalysis\bin\Debug\SourceCodeAnalysis.pdb

     文件      11608  2013-05-27 00:44  SourceCodeAnalysis\bin\Debug\SourceCodeAnalysis.vshost.exe

     文件      13477  2013-05-27 00:36  SourceCodeAnalysis\FrmLinesOfCodeStatistics.cs

     文件      15620  2013-05-27 00:34  SourceCodeAnalysis\FrmLinesOfCodeStatistics.Designer.cs

     文件       7152  2013-05-27 00:34  SourceCodeAnalysis\FrmLinesOfCodeStatistics.resx

     文件       5482  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        218  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug\GenerateResource.read.1.tlog

     文件       1026  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug\GenerateResource.write.1.tlog

     文件       1295  2013-05-27 00:44  SourceCodeAnalysis\obj\x86\Debug\SourceCodeAnalysis.csproj.FileListAbsolute.txt

     文件      19456  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug\SourceCodeAnalysis.exe

     文件        180  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug\SourceCodeAnalysis.FrmLinesOfCodeStatistics.resources

     文件      38400  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug\SourceCodeAnalysis.pdb

     文件        180  2013-05-26 12:11  SourceCodeAnalysis\obj\x86\Debug\SourceCodeAnalysis.Properties.Resources.resources

     文件       4608  2013-05-26 12:05  SourceCodeAnalysis\obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        498  2013-05-24 22:27  SourceCodeAnalysis\Program.cs

     文件       1428  2013-05-24 22:25  SourceCodeAnalysis\Properties\AssemblyInfo.cs

     文件       2874  2013-05-26 12:05  SourceCodeAnalysis\Properties\Resources.Designer.cs

     文件       5612  2013-05-24 22:25  SourceCodeAnalysis\Properties\Resources.resx

     文件       1116  2013-05-26 12:05  SourceCodeAnalysis\Properties\Settings.Designer.cs

     文件        249  2013-05-24 22:25  SourceCodeAnalysis\Properties\Settings.settings

     文件       3607  2013-05-26 12:11  SourceCodeAnalysis\SourceCodeAnalysis.csproj

     目录          0  2013-05-26 12:05  SourceCodeAnalysis\obj\x86\Debug\TempPE

     目录          0  2013-05-27 00:36  SourceCodeAnalysis\obj\x86\Debug

     目录          0  2013-05-26 12:11  SourceCodeAnalysis\bin\Debug

     目录          0  2013-05-24 22:26  SourceCodeAnalysis\bin\Release

     目录          0  2013-05-24 22:25  SourceCodeAnalysis\obj\x86

     目录          0  2013-05-24 22:26  SourceCodeAnalysis\bin

     目录          0  2013-05-24 22:25  SourceCodeAnalysis\obj

............此处省略5个文件信息

评论

共有 条评论