Skip to content

ESP32: os.listdir with non-ASCII chars #8300

@Narsskrarc

Description

@Narsskrarc

Hi,

I have a file on the SD-Card names "Frühstück.wav". With os.listdir it is displayed as "Frhstck.wav", When I convert it to bytes() I can see it is b"Fr\x81hst\x81ck.wav" in fact.

I have to compare the name to a string named "Frühstück.wav". But I can't convert neither the string from os.listdir in unicode nor can I create a string which is equal to the string from os.listdir.
I found the hint to use a unicode directory for os.listdir(). I tried to decode(anything) the b"...", but it throws an UnicodeError no matter which encoding I try. The other way round I can encode the unicode string with any encoding, it gets the same byte string:
"Frühstück.wav".encode('UTF-8') -> b'Fr\xc3\xbchst\xc3\xbcck.wav'
"Frühstück.wav".encode('ASCII') -> b'Fr\xc3\xbchst\xc3\xbcck.wav'
"Frühstück.wav".encode('ISO-8859-1') -> b'Fr\xc3\xbchst\xc3\xbcck.wav'

What is the right way to handle non-ascii-filenames with micropython?

Metadata

Metadata

Assignees

No one assigned

    Labels

    unicodeBugs and enhancements related to Unicode/UTF-8 support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions