Created
June 19, 2015 20:11
-
-
Save mkropat/c7741d92fb3ab580f332 to your computer and use it in GitHub Desktop.
Find files with the most lines of code in a project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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