FindFirstFileEx不区分大小写 [英] FindFirstFileEx doesn't operate case sensitive

查看:199
本文介绍了FindFirstFileEx不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我正在使用一个宏,如果给定路径的大小写与驱动器上的本地路径不相等,那么我似乎可以使用该宏,因此我首先需要验证该路径是否按大小写存在。不幸的是(对我而言) Directory.Exists()不区分大小写。

Since I'm using a macro which seems to work if the given path is case unequal to the local path on the drive I first need to validate wether the path is case-wise existing or not. Unfortunately (in my case) Directory.Exists() is not case sensitive.

所以我尝试了 FindFirstFileEx ,其中 dwAdditionalAttributes 设置为 1 代表 FIND_FIRST_EX_CASE_SENSITIVE 。但是,这似乎对我不起作用。我的本地路径是 C:\Dir1\Dir2\Dir3 。我比较的路径是 C:\dir1\Dir2\Dir3 。不幸的是,我总是得到 Dir3 的结果。如果案件不匹配,我本来希望得到一个空结果。

So I tried FindFirstFileEx with dwAdditionalAttributes set to 1 which stands for FIND_FIRST_EX_CASE_SENSITIVE. However it seems not work for me. My local path is C:\Dir1\Dir2\Dir3. The path I compare is C:\dir1\Dir2\Dir3. Unfortunately I always get Dir3 as a result. I would have expected an empty result if the cases don't match.

我的错是什么?

string dir = @"C:\Dir1\Dir2\Dir3" + '\0';
int FIND_FIRST_EX_CASE_SENSITIVE = 1;
WIN32_FIND_DATA fi;

IntPtr h = FindFirstFileEx( dir,
                            FINDEX_INFO_LEVELS.FindExInfoStandard,
                            out fi,
                            FINDEX_SEARCH_OPS.FindExSearchNameMatch,
                            IntPtr.Zero,
                            FIND_FIRST_EX_CASE_SENSITIVE);


推荐答案

此功能取决于注册表项<$ c的值$ c> HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\obcase不敏感设置为0,这不是默认值。

This functionality depends on value of registry key HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\obcaseinsensitive being set set to 0, which is not the default.

换句话说,它取决于基础文件系统设置,而不是API本身。

In other words, it depends on underlying file system settings, not the API itself.

此处有更多详细信息: http://www.siao2.com/2010/12/08/10101148.aspx

more details here: http://www.siao2.com/2010/12/08/10101148.aspx

这篇关于FindFirstFileEx不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆