param(
    # Where your subfolders & *_cry.ogg files live
    [string]$folderPath = "C:\Users\mrsal\Downloads\Current\assets\cobblemon\sounds\pokemon",
    
    # (Optional) Where you want to output the list
    [string]$outputFile = ""
)

Write-Host "Scanning for '*_cry.ogg' files in: $folderPath"
Write-Host

# Recursively find any .ogg file ending with "_cry.ogg"
$files = Get-ChildItem -Path $folderPath -Recurse -Filter "*_cry.ogg" -ErrorAction SilentlyContinue

if ($files.Count -eq 0) {
    Write-Host "No '*_cry.ogg' files found."
    Write-Host "Press Enter to exit."
    [Console]::ReadLine() | Out-Null
    return
}

Write-Host "Found $($files.Count) file(s). Listing Pokémon names..."
Write-Host

# Collect Pokémon names (stripping off "_cry" from the file's basename)
$pokemonNames = foreach ($file in $files) {
    $file.BaseName -replace "_cry$",""
}

# Display each Pokémon name
$pokemonNames | ForEach-Object { Write-Host $_ }

# If an output file path was provided, save the list
if ($outputFile -ne "") {
    try {
        $pokemonNames | Out-File -FilePath $outputFile -Encoding UTF8
        Write-Host "`nList saved to: $outputFile"
    }
    catch {
        Write-Host "`nFailed to write to file '$outputFile': $($_.Exception.Message)"
    }
}

Write-Host "`nPress Enter to exit..."
[Console]::ReadLine() | Out-Null
