Created
April 19, 2015 04:24
-
-
Save SirkleZero/06b9a6154746b4b824c5 to your computer and use it in GitHub Desktop.
A simple Powershell script to analyze a solution directory and provide simple code statistics.
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 ( | |
[ValidateScript({$_ | Test-Path -PathType Container})] | |
[Parameter(Mandatory=$true)] | |
[string] $path | |
) | |
[string[]] $extensions = | |
".asp", | |
".Domain", | |
".Repository", | |
".SqlServer", | |
".Models", | |
".Master", | |
".Web", | |
".ErrorManager", | |
".Core", | |
".ApplicationServices", | |
".Tests", | |
".Data", | |
".Service", | |
#".AhcoCustomDb", | |
".Extensions", | |
".gitattributes", | |
".gitignore", | |
#".merge_file_a14588", | |
".sln", | |
".md", | |
#".StyleCop", | |
".csproj", | |
".cs", | |
".config", | |
".scproj", | |
".xml", | |
".item", | |
".asax", | |
#".pubxml", | |
".cshtml", | |
".nuspec", | |
#".css", | |
#".woff", | |
#".eot", | |
#".svg", | |
#".ttf", | |
".html", | |
".json", | |
#".png", | |
#".gif", | |
".js", | |
".ts", | |
".ashx", | |
".ascx", | |
".aspx", | |
#".targets", | |
".asmx", | |
".sqlproj", | |
".sql", | |
#".orig", | |
#".role", | |
".scss", | |
#".dll", | |
#".nupkg", | |
".xdt", | |
".ps1", | |
".txt", | |
#".exclude", | |
".pp", | |
".proj" | |
$stats = New-Object -TypeName PSObject | |
Add-Member -InputObject $stats -MemberType NoteProperty -Name lines -Value 0 | |
Add-Member -InputObject $stats -MemberType NoteProperty -Name words -Value 0 | |
Add-Member -InputObject $stats -MemberType NoteProperty -Name characters -Value 0 | |
Add-Member -InputObject $stats -MemberType NoteProperty -Name files -Value 0 | |
function CanProcess($item){ | |
return $extensions.Contains($item.Extension.ToLower()) -And !$item.FullName.Contains("\packages\") -And !$item.FullName.Contains("\obj\") -And !$item.FullName.Contains("\bin\") | |
} | |
function Traverse(){ | |
gci "$path" -recurse -File | % { | |
if(CanProcess($_)){ | |
$tmp = (Get-Content $_.FullName | Measure-Object -word -line -character -ignorewhitespace) | |
$stats.lines += $tmp.lines | |
$stats.words += $tmp.words | |
$stats.characters += $tmp.characters | |
$stats.files++ | |
Write-Host $_.FullName " lines: " $tmp.lines | |
} | |
} | |
} | |
Write-Host "Running..." | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics") | |
$sw = new-object system.diagnostics.stopwatch | |
$sw.Start() | |
Traverse | |
Write-Host "Lines | Words | Characters | Files" | |
Write-Host "==================================" | |
Write-Host $stats.lines " " $stats.words " " $stats.characters " " $stats.files | |
[int[]] $clippy = $stats.lines, $stats.words, $stats.characters, $stats.files | |
$clippy | clip | |
$sw.Stop() | |
Write-Host "Completed in " $sw.Elapsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment