Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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

This comment has been minimized.

Copy link
Owner Author

@martin9700 martin9700 commented Mar 2, 2016

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