Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-platform filenames with accents #6

Closed
Wtower opened this issue Mar 21, 2022 · 0 comments
Closed

Cross-platform filenames with accents #6

Wtower opened this issue Mar 21, 2022 · 0 comments

Comments

@Wtower
Copy link
Owner

Wtower commented Mar 21, 2022

There is an issue with filenames with accents across Mac/Win:

>>> str_win = 'Τρέχοντα υπόλοιπα προμηθευτών.xlsx' # Copied from Explorer
>>> str_mac = 'Τρέχοντα υπόλοιπα προμηθευτών.xlsx' # Copied from Finder
>>> str_win == str_mac
False

>>> str_win.encode('utf-8')
b'\xce\xa4\xcf\x81\xce\xad\xcf\x87\xce\xbf\xce\xbd\xcf\x84\xce\xb1 \xcf\x85\xcf\x80\xcf\x8c\xce\xbb\xce\xbf\xce\xb9\xcf\x80\xce\xb1 \xcf\x80\xcf\x81\xce\xbf\xce\xbc\xce\xb7\xce\xb8\xce\xb5\xcf\x85\xcf\x84\xcf\x8e\xce\xbd.xlsx'

>>> str_mac.encode('utf-8')
b'\xce\xa4\xcf\x81\xce\xb5\xcc\x81\xcf\x87\xce\xbf\xce\xbd\xcf\x84\xce\xb1 \xcf\x85\xcf\x80\xce\xbf\xcc\x81\xce\xbb\xce\xbf\xce\xb9\xcf\x80\xce\xb1 \xcf\x80\xcf\x81\xce\xbf\xce\xbc\xce\xb7\xce\xb8\xce\xb5\xcf\x85\xcf\x84\xcf\x89\xcc\x81\xce\xbd.xlsx'

>>> import unicodedata
>>> unicodedata.normalize('NFD', str_win) == str_mac
True

>>> str_win == unicodedata.normalize('NFC', str_mac)
True

>>> from pathlib import Path
>>> Path(str_win).is_file() # on Windows
True

>>> Path(str_win).is_file() # on Mac
True

>>> from pathlib import Path
>>> Path(str_mac).is_file() # on Windows
False

>>> Path(str_mac).is_file() # on Mac
True

Therefore, normalize with unicodedata.normalize('NFC', str_mac_or_win) to solve the issue.

https://nedbatchelder.com/blog/201106/filenames_with_accents.html

Remove the fuzzy matching of filenames previously attempted to solve the issue.

@Wtower Wtower closed this as completed in bc09621 Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant