Last active
August 29, 2015 14:09
-
-
Save yumaikas/2b15b8bcfd4800c7dc9d to your computer and use it in GitHub Desktop.
This is a small PowerShell Script for counting the
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
#A small script for counting lines of code for projects in a list of C# code | |
# directories. | |
# Inspired by | |
# http://www.limilabs.com/blog/source-lines-of-code-count-using-powershell | |
# In the interest of berevity, I've used the following standard powershell alias's | |
# ls = Get-ChildItem | |
# % = Foreach-Object | |
# ? = Where-Object | |
# sort = Sort-Object | |
ls -Directory | % { | |
$Local:count = (dir $_ -filter *.cs -recurse | | |
# Trying to not count any lines that are part of designers. | |
? { $_.FullName -notmatch '.*(obj|bin|Properties|Designer|g\.cs).*' } | | |
select-string "^\s*$" -notMatch | | |
select-string "^\s*//" -notMatch | | |
select-string "^\s*/\*" -notMatch | | |
select-string "^\s*\*.*(?:\*/)?\s*$" -notMatch | | |
select-string "^\s*(?:\{|\})\s*$" -notMatch).Count | |
if ($Local:count -gt 0) | |
{ | |
[PSCustomObject]@{ | |
name = $_.Name -as [string] | |
count = $Local:count -as [int] | |
} | |
} | |
} | sort count -Descending | % {$_} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment