Skip to content

Instantly share code, notes, and snippets.

@jehugaleahsa jehugaleahsa/loc.ps1
Created Aug 18, 2017

Embed
What would you like to do?
A simple PowerShell script to count the lines of code in a solution
$path = "C:\path\to\solution\folder"
$files = Get-ChildItem -Path $path -Include *.cs,*.ts,*.vb -Recurse `
| ? { $_.FullName -notmatch ".*\\obj\\.*" } `
| ? { $_.FullName -notmatch ".*\\node_modules\.*" }
$shortNames = $files | % {
$fullName = $_.FullName
$lines = [System.IO.File]::ReadAllLines($fullName)
$lines = $lines | ? { -not [System.String]::IsNullOrWhiteSpace($_) }
$data = @{};
$data.Name = $_.Name
$data.LineCount = $lines.Length
New-Object -TypeName PSObject -Property $data
} | Sort-Object -Property LineCount -Descending
#$biggest = $shortNames | Select-Object -First 100
$count = $shortNames | Measure-Object -Sum -Average -Property LineCount
Write-Host $count.Sum $count.Average
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.