import os
import re

# Převodní tabulka sestavená z pozorovaných dat
TABLE = {
    0x83: 'č',
    0xE1: 'á',  # $'\341'
    0xED: 'í',
    0xFD: 'ý',
    0xFE: 'š',
    0xE0: 'ů',
    0xB2: 'ř',
    0xB3: 'Ř',
    0xCF: 'ě',
    # doplň další až narazíš
}

def fix_filename(raw_bytes):
    result = []
    for b in raw_bytes:
        if b in TABLE:
            result.append(TABLE[b])
        elif b < 0x80:
            result.append(chr(b))
        else:
            result.append(f'[0x{b:02X}]')  # neznámý bajt viditelně
    return ''.join(result)

# Projdi aktuální adresář a přejmenuj
for entry in os.scandir('.'):
    raw = os.fsencode(entry.name)
    # Přeskočit pokud je název čistě ASCII nebo validní UTF-8
    try:
        raw.decode('utf-8')
        continue  # validní UTF-8, přeskočit
    except UnicodeDecodeError:
        pass

    new_name = fix_filename(raw)
    if '[0x' in new_name:
        print(f'NEZNÁMÝ BAJT: {entry.name!r} -> {new_name}')
        continue
    print(f'{entry.name!r}  ->  {new_name!r}')
    os.rename(entry.name, new_name)  # odkomentuj až ověříš výstup
