Created
September 8, 2017 10:35
-
-
Save fcharlie/fb7be93a7ef248cae19e96d23ea4e151 to your computer and use it in GitHub Desktop.
Project sources line counts
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
#!/usr/bin/env powershell | |
# ----------- | |
param( | |
[String]$ProjectDir | |
) | |
Function Get-FileLines { | |
param( | |
[string]$Path | |
) | |
$lines = 0 | |
$reader = New-Object IO.StreamReader $Path | |
while ($reader.ReadLine() -ne $null) { $lines++ } | |
$reader.Close() # don't forget to do this. Ideally put this in a try/finally block to make sure it happens | |
return $lines | |
} | |
Function GetDirlineCounts { | |
param( | |
[string]$Path | |
) | |
$xt = 0 | |
Get-ChildItem -Path $Path -Recurse -Include *.c, *.cc, *.cxx, *.h, *.hpp |ForEach-Object { | |
$counts = Get-FileLines -Path $_.FullName | |
Write-Host "file: $($_.FullName) line: $counts" | |
$xt += $counts | |
} | |
return $xt | |
} | |
[long]$total = 0 | |
$dirs = @( | |
"include", | |
"tools", | |
"utils", | |
"server", | |
"sources", | |
"cratos" | |
) | |
foreach ($d in $dirs) { | |
if (Test-Path "$ProjectDir/$d") { | |
$total += GetDirlineCounts -Path "$ProjectDir/$d" | |
} | |
} | |
Write-Host "total: $total" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment