Windows 环境中的文件路径不区分大小写?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7199039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:43:41  来源:igfitidea点击:

File paths in Windows environment not case sensitive?

windows

提问by burnt1ce

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

假设 Windows 本地和网络文件路径不区分大小写是否安全?

采纳答案by Reed Copsey

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.

是的。Windows(本地)文件系统,包括 NTFS,以及 FAT 和变体,不区分大小写(通常)。网络文件系统的底层实现可能区分大小写,但是,大多数允许 Windows 访问它的软件(例如SMB)会自动使区分大小写的文件系统显示为对 Windows 不区分大小写。

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

有关详细信息,我会阅读Wikipedia 文章中关于 filenames 的部分

回答by Chris Becke

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.

Windows 上的区分大小写实际上是在应用程序打开文件的方式中实现的。NTFS 可以是区分大小写的文件系统,可以愉快地存储文件,在同一目录中具有相同名称的文件仅大小写不同。

On Windows all files are ultimately opened via the CreateFileAPI - If the FILE_FLAG_POSIX_SEMANTICSflag 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_SEMANTICSis 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.

在 Windows 上,所有文件最终都通过CreateFileAPI打开- 如果将FILE_FLAG_POSIX_SEMANTICS标志传递给调用(并且正在访问的文件系统本地区分大小写),则文件将根据精确的名称匹配打开。如果FILE_FLAG_POSIX_SEMANTICS未通过,则文件系统会打开不区分大小写的文件,并将打开具有匹配名称的文件之一。如果有多个,则不确定实际打开了哪一个。

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.

Windows 上的大多数 C 和 C++ 运行时实现不提供对此机制的任何访问,并且从不使用此标志,因此访问区分大小写行为的唯一方法是直接使用 Windows API。

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.

tl;dr - 您的语言运行时可能会将您的文件系统暴露为不区分大小写或保留大小写。如果您直接使用 Windows API,您可以完全区分大小写访问受支持的文件系统。

回答by Brad

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/

我在 Windows 上运行区分大小写的文件系统。我在每个目录的基础上使用它:https: //devblogs.microsoft.com/commandline/per-directory-case-sensivity-and-wsl/

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

这会破坏所有不考虑它的 Windows 应用程序,并执行诸如将文件请求转换为全部小写的操作。

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.

我建议每个人在为 Windows 构建应用程序时都假设一个区分大小写的文件系统。因为假设不区分大小写,您只会遇到麻烦。