private StatModel StatFolder(string filename, ref DataTable dt, int curPathLen) { DirectoryInfo di = new DirectoryInfo(filename); StatModel sm = new StatModel(""); if (di.Exists) { if (di.FullName.Length == curPathLen) { dt.Rows.Add("\\", 0, 0, 0, 0); } else { dt.Rows.Add(di.FullName.Substring(curPathLen), 0, 0, 0, 0); } int index = dt.Rows.Count - 1; try { DirectoryInfo[] dis = di.GetDirectories(); foreach (DirectoryInfo subdi in dis) { StatModel m = StatFolder(subdi.FullName, ref dt, curPathLen); sm.BlankLines += m.BlankLines; sm.CodeLines += m.CodeLines; sm.CommentLines += m.CommentLines; } } catch { } try { FileInfo[] fis = di.GetFiles(); foreach (FileInfo fi in fis) { StatModel m = StatFile(fi.FullName, ref dt, curPathLen); if (m.IsValid) { sm.BlankLines += m.BlankLines; sm.CodeLines += m.CodeLines; sm.CommentLines += m.CommentLines; } } } catch { } if (sm.TotalLines > 0) { dt.Rows[index][1] = sm.BlankLines; dt.Rows[index][2] = sm.CodeLines; dt.Rows[index][3] = sm.CommentLines; dt.Rows[index][4] = sm.TotalLines; } else { dt.Rows.RemoveAt(index); } } return(sm); }