这些天找工作,在描述自己的语言技能时,总不知道该怎么说比较清楚。精通?不敢……
熟悉?多少才算……
一般?
了解?
索性今天写了个统计代码量的小工具,把最近在做的项目放进去跑了一下,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] + " "; } } } }
【工具下载】