Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Code Analysis

RSS
Modified on Tue, Dec 31, 2019, 12:47 PM by Administrator Categorized as ┬ĚNet Framework

C# Code

var fileExtensions = new[] { ".cs", ".ts", ".html",".css" };

var files = Directory
    .GetFiles(rootPath, "*.*", SearchOption.AllDirectories)
    .ToList()
    .Where(f => 
        !f.Contains(@"\bin\")
        && !f.Contains(@"\obj\")
        && !f.Contains(".min.")
        && fileExtensions.Any(fe => f.EndsWith(fe))
        );

var totalLineQty = 0;
var fileNum = 0;
var fileCounts = new Dictionary<string, int>();

foreach (var ext in fileExtensions)
    fileCounts.Add(ext, 0);

var calc = new EtcCalculator(files.Count());
var etc = DateTime.Now;

foreach (var file in files)
{
    fileNum++;

    Console.WriteLine($"Processing file {fileNum} of {files.Count()} - ETC = {etc:MM/dd/yyyy h:mm tt}");

    var ext = Path.GetExtension(file).ToLower();

    fileCounts[ext] += 1;

    totalLineQty += File.ReadAllLines(file).Count();

    etc = calc.GetEtc(fileNum);
}

foreach (var key in fileCounts.Keys)
{
    Debug.Print($"Total '{key}' file(s): {fileCounts[key]}");
}
Debug.Print($"Total Files:   {files.Count()}");
Debug.Print($"Lines of Code: {totalLineQty:#,##0}");

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2020, Patrick Jasinski.