private void Count() { var folderPath = folderTextBox.Text; var fileMask = fileMaskEdit.Text; if (!Directory.Exists(folderPath)) { var message = string.Format("Folder \"{0}\" does not exist.", folderPath); MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Hand); folderTextBox.Focus(); } else { if (fileMask == null || fileMask.Trim().Length == 0) { var message = string.Format("Please specify a search pattern.", folderPath); MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.Hand); fileMaskEdit.Focus(); } var fileFinder = new FileFinder(); fileFinder.AddFiles(folderPath, fileMask, true); var lineCounter = new Logic.LineCounter(); lineCounter.MinNonWhitespaceChars = Convert.ToInt32(minimalCharCountUpDown.Value); for (var index = 0; index < fileFinder.Count; ++index) { lineCounter.Add(fileFinder[index]); } lineCounter.Count(); totalLineCountTextBox.Text = string.Format("{0:N0}", lineCounter.TotalLineCount); filesListView.BeginUpdate(); try { filesListView.Items.Clear(); for (var index = 0; index < lineCounter.FileCount; ++index) { filesListView.Items.Add(new ListViewItem(new string[3] { Path.GetFileName(lineCounter[index].Filename), lineCounter[index].LineCount.ToString(), Path.GetDirectoryName(lineCounter[index].Filename) }) { Tag = lineCounter[index].LineCount }); } } finally { filesListView.EndUpdate(); } } }