Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Created February 10, 2013 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiftkey/4748988 to your computer and use it in GitHub Desktop.
Save shiftkey/4748988 to your computer and use it in GitHub Desktop.
Sorting code files by line count using Powershell (because I want to tackle the simplest ones first)
$sortedFiles = @()
$files = Get-ChildItem D:\Code\github\shiftkey\UbiqRT-Storage\Storage\ -Filter *.cs -Recurse
ForEach($file in $files) {
$count = (Get-Content $file.FullName | Measure-Object).Count
if ($count -gt 0) {
$fullName =
$obj = New-Object System.Object
$obj | Add-Member -type NoteProperty -name Name -value $file.Name
$obj| Add-Member -type NoteProperty -name Count -value $count
$sortedFiles += $obj
}
}
$sortedFiles | Sort-Object Count
@lynn
Copy link

lynn commented Oct 26, 2018

Cool! I found yours via Google, and then ended up writing my own that's easier to use and modify from the command line:

Ls . -Filter *.tsx -Recurse | %{ $_ | Add-Member LineCount (Cat $_.FullName | Measure-Object -Line).Lines; $_ } | Sort LineCount

Tack on something like … | Ft FullName, LineCount to taste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment