Created
March 2, 2016 19:45
-
-
Save martin9700/4c5a7dc448ee2cee7b59 to your computer and use it in GitHub Desktop.
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
[CmdletBinding()] | |
Param ( | |
[ValidateScript({ Test-Path $_ } )] | |
[string]$Path = "c:\Test" | |
) | |
$ResultHash = @{ | |
"1-0" = 0 | |
"0-1" = 0 | |
"1/2-1/2" = 0 | |
} | |
$DisplayHash = @{ | |
"1-0" = "White" | |
"0-1" = "Black" | |
"1/2-1/2" = "Draw" | |
} | |
$Start = Get-Date | |
$Results = ForEach ($Dir in (Get-ChildItem $Path -Directory | Sort Name | Select -First 10)) | |
{ | |
ForEach ($File in (Get-ChildItem "$($Dir.FullName)\*.pgn" -File)) | |
{ | |
$RawFile = (New-Object System.IO.StreamReader -Argument $File.FullName).ReadToEnd() | |
ForEach ($Group in ($RawFile | Select-String -AllMatches -Pattern '\[Result \"(.*)\"').Matches) | |
{ | |
$ResultHash[$Group.Groups[1].Value] ++ | |
} | |
} | |
} | |
$ResultHash.Keys | Where { $_ -ne "*" } | Sort | Select @{Name="Winner";Expression={ $DisplayHash[$_] }},@{Name="Count";Expression={ $ResultHash[$_] }} | |
Write-Verbose $(New-TimeSpan -Start $Start -End (Get-Date)) -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First run was 4 minutes 20 seconds (did screen shot that one). Second run was even better!