Skip to content

Instantly share code, notes, and snippets.

@mkropat
Created June 19, 2015 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkropat/c7741d92fb3ab580f332 to your computer and use it in GitHub Desktop.
Save mkropat/c7741d92fb3ab580f332 to your computer and use it in GitHub Desktop.
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