[Resources] PowerShell script to import files from supermemo to Anki

I’ve created a PowerShell script that transforms SuperMemo files in “QA text file” format into a format compatible with Anki import. Here’s the script:



# Pedir al usuario el nombre del fichero
$entrada = Read-Host "Introduce el nombre del fichero a transformar (por ejemplo: datos.txt)"

# Comprobar si existe
if (-not (Test-Path $entrada)) {
    Write-Host "El fichero '$entrada' no existe." -ForegroundColor Red
    exit
}

$q = ""
$a = ""
$result = @()

Get-Content $entrada | ForEach-Object {
    if ($_ -match "^Q:") {
        $q = $_.Substring(2).Trim()
    }
    elseif ($_ -match "^A:") {
        $a = $_.Substring(2).Trim()
        $result += "$q;$a"
    }
}

# Crear nombre de salida
$salida = [System.IO.Path]::ChangeExtension($entrada, $null) + "_salida.txt"

# Guardar resultado
$result | Set-Content $salida -Encoding UTF8

Write-Host "Transformación completada. Archivo generado: $salida" -ForegroundColor Green


1 Like