代碼量統計工具

這些天找工做,在描述本身的語言技能時,總不知道該怎麼說比較清楚。精通?不敢……python

熟悉?多少纔算……數組

通常?ide

瞭解?工具

索性今天寫了個統計代碼量的小工具,把最近在作的項目放進去跑了一下,python果真只是「通常」瞭解,這麼少的量……this

貼個圖:spa

代碼:code

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

工具下載orm

相關文章
相關標籤/搜索