代码量统计工具

这些天找工作,在描述自己的语言技能时,总不知道该怎么说比较清楚。精通?不敢……

熟悉?多少才算……

一般?

了解?

索性今天写了个统计代码量的小工具,把最近在做的项目放进去跑了一下,python果然只是“一般”了解,这么少的量……

贴个图:

代码:

复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace countLinesCsharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<int> countLines(string[] extensions, string folderPath) {

            //初始化统计数组
            List<int> counts = new List<int>();
            for (int i = 0; i < extensions.Length; i++)
            {
                counts.Add(0);
            }

            //遍历文件夹进行统计
            DirectoryInfo rootFolder = new DirectoryInfo(folderPath);
            List<DirectoryInfo> folders = new List<DirectoryInfo>();

            folders.Add(rootFolder);
            int index = 0;
            while(index != folders.Count)
            {
                DirectoryInfo folder = folders[index];

                foreach (DirectoryInfo tempFolder in folder.GetDirectories()) {
                    folders.Add(tempFolder);
                }

                FileInfo[] files = folder.GetFiles();

                foreach (FileInfo file in files)
                {
                    for (int i = 0; i < extensions.Length; i++)
                    {
                        if (extensions[i].Equals(file.Extension))
                        {
                            int lines = 0;
                            StreamReader read = file.OpenText();
                            while (null != read.ReadLine()) {
                                lines++;
                            }
                            counts[i] += lines;
                        }
                    }
                }
                index++;
            }
            return counts;
        }

        private void chooseDirButt_Click(object sender, EventArgs e)
        {
            //选择文件夹
            FolderBrowserDialog folderDlg = new FolderBrowserDialog();
            folderDlg.ShowDialog();
            this.dirPathLabel.Text = folderDlg.SelectedPath;
            startButt.Enabled = true;
        }

        private void startButt_Click(object sender, EventArgs e)
        {
            //清空输出框
            result.Text = "";

            //获得后缀名类型
            string[] extensions = this.extensions.Text.Split();

            List<int> count = countLines(extensions, this.dirPathLabel.Text);

            for(int i = 0; i < count.Count; i++){
                result.Text += extensions[i] + ":" + count[i] + "\r\n";
            }
        }
    }
}
View Code
复制代码

工具下载

 

posted @   elar  阅读(9664)  评论(3编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2012-09-19 云计算 读paper笔记
点击右上角即可分享
微信分享提示