File paths in Windows environment not case sensitive?

前端 未结 3 1228
野的像风
野的像风 2020-11-27 06:01

Is it safe to assume that Windows local and network file paths are NOT case sensitive?

相关标签:
3条回答
  • 2020-11-27 06:30

    I run case sensitive files system on windows. I use it on a per-directory basis: https://devblogs.microsoft.com/commandline/per-directory-case-sensitivity-and-wsl/

    This breaks all windows applications that do not account for it and do things like convert file requests to all lowercase.

    But I wouldn't rule out others running case sensitivity on entire hard drives and network resources.

    Typically only developers will do this though so it entirely depends on your use case.

    If you are making an application for advanced power users I'd say it is not a safe assumption.

    I'd recommend everyone assume a case sensitive file system when building applications for windows. Because you only run into trouble assuming non-case sensitive.

    0 讨论(0)
  • 2020-11-27 06:54

    Yes. Windows (local) file systems, including NTFS, as well as FAT and variants, are case insensitive (normally). The underlying implementation of a network file system may be case sensitive, however, most software that allows Windows to access it (such as SMB) will automatically make case sensitive file systems appear as case insensitive to Windows.

    For details, I'd read the section in the Wikipedia article on filenames.

    0 讨论(0)
  • 2020-11-27 06:55

    Case sensitivity on Windows is actually implemented in how the application opens the files. NTFS can be a case-sensitive file system and can happily store files, with identical names differing only by case in the same directory.

    On Windows all files are ultimately opened via the CreateFile API - If the FILE_FLAG_POSIX_SEMANTICS flag is passed to the call (and the file system being accessed is natively case-sensitive) then the file will be opened based on an exact name match. If FILE_FLAG_POSIX_SEMANTICS is not passed then the filesystem does a case-insensitive file open and will open one of the files with a matching name. If there is more than one it's undefined as to which one is actually opened.

    Most C and C++ runtime implementations on Windows do not provide any access to this mechanism and never use this flag so the only way to get access to case-sensitive behaviors is to use the Windows API directly.

    tl;dr - Your language runtime probably exposes your filesystem as case insensitive or case preserving. You can, if you use the windows API directly, access supported filesystems fully case senstive.

    0 讨论(0)
提交回复
热议问题