Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find files with the most lines of code in a project
param(
[string] $Filter,
[switch] $Recurse,
[int] $Top
)
function main {
Get-ChildItem -Recurse:$Recurse -Filter $Filter |
where { -not (Test-Path $_ -PathType Container) } |
Measure-Lines |
sort -Property Lines -Descending |
Select-Top $Top |
Format-Table -AutoSize
}
function Measure-Lines {
process {
New-Object PSObject -Property @{
File = Resolve-Path $_.FullName -Relative;
Lines = (Get-Content $_.FullName | measure -Line).Lines;
}
}
}
function Select-Top {
param([int] $Top)
if ($top -eq 0) {
$input
}
else {
$input | select -First $Top
}
}
main
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.