Skip to content

Instantly share code, notes, and snippets.

@kaubu
Created November 7, 2025 22:11
Show Gist options
  • Select an option

  • Save kaubu/e25460156e476542c64424a7fa31c130 to your computer and use it in GitHub Desktop.

Select an option

Save kaubu/e25460156e476542c64424a7fa31c130 to your computer and use it in GitHub Desktop.
$RootFolder = ".\"
$chdFiles = Get-ChildItem -Path $RootFolder -Filter "*.chd" -File
$multiDiscGames = @{}
foreach ($file in $chdFiles) {
if ($file.Name -match '^(.+?)\s+\(Disc\s+\d+\)') {
$gameName = $matches[1]
if (-not $multiDiscGames.ContainsKey($gameName)) {
$multiDiscGames[$gameName] = @()
}
$multiDiscGames[$gameName] += $file
}
}
foreach ($gameName in $multiDiscGames.Keys) {
$folderName = "$gameName.m3u"
$folderPath = Join-Path (Resolve-Path $RootFolder) $folderName
New-Item -Path $folderPath -ItemType Directory -Force | Out-Null
$discFiles = $multiDiscGames[$gameName] | Sort-Object Name
$m3uFilePath = Join-Path $folderPath "$gameName.m3u"
$discFileNames = $discFiles | ForEach-Object { $_.Name }
$discFileNames | Out-File -LiteralPath $m3uFilePath -Encoding ASCII
Write-Host "Created $folderName with $($discFiles.Count) discs"
foreach ($discFile in $discFiles) {
Move-Item -LiteralPath $discFile.FullName -Destination $folderPath
}
}
Write-Host "`nDone! Processed $($multiDiscGames.Count) multi-disc games."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment