Skip to content

Instantly share code, notes, and snippets.

@luser
Created February 1, 2021 17:03
Show Gist options
  • Save luser/e68ab57a0ba0c66cb4d7e668d821e319 to your computer and use it in GitHub Desktop.
Save luser/e68ab57a0ba0c66cb4d7e668d821e319 to your computer and use it in GitHub Desktop.
Canonicalize filename case in system Python 2.7 on macOS
#!/usr/bin/python
from __future__ import print_function
from Carbon.File import FSPathMakeRef
import os
import sys
import unicodedata
def actual_path(path):
ref, _ = FSPathMakeRef(path)
out = unicodedata.normalize('NFC', ref.FSRefMakePath().decode('utf-8'))
if path.endswith(os.path.sep) and not out.endswith(os.path.sep):
return out + os.path.sep
return out
def main():
for p in sys.argv[1:]:
print(actual_path(p))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment