pythonfilesystemsntfshfs+

Check if file system is case-insensitive in Python


Is there a simple way to check in Python if a file system is case insensitive? I'm thinking in particular of file systems like HFS+ (OSX) and NTFS (Windows), where you can access the same file as foo, Foo or FOO, even though the file case is preserved.


Solution

  • import os
    import tempfile
    
    # By default mkstemp() creates a file with
    # a name that begins with 'tmp' (lowercase)
    tmphandle, tmppath = tempfile.mkstemp()
    if os.path.exists(tmppath.upper()):
        # Case insensitive.
    else:
        # Case sensitive.