Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Created September 12, 2013 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayrx/6536184 to your computer and use it in GitHub Desktop.
Save Ayrx/6536184 to your computer and use it in GitHub Desktop.
A code snippet to find the case sensitive version of path name on the system given a case insensitive version.
import os
def get_case_sensitive_pathname(path, top):
for root, dirs, files in os.walk(top):
for d in dirs:
if os.path.join(root, d).lower() == path.lower():
return os.path.join(root, d)
for f in files:
if os.path.join(root, f).lower() == path.lower():
return os.path.join(root, f)
return path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment