Skip to content

Instantly share code, notes, and snippets.

@martin9700
Created March 2, 2016 19:45
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 martin9700/4c5a7dc448ee2cee7b59 to your computer and use it in GitHub Desktop.
Save martin9700/4c5a7dc448ee2cee7b59 to your computer and use it in GitHub Desktop.
[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
@martin9700
Copy link
Author

First run was 4 minutes 20 seconds (did screen shot that one). Second run was even better!
run1

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