gpt4 book ai didi

c++ - 是否有不搜索短文件名的 Windows FindFirstFile/FindNextFile API 的替代方法?

转载 作者:可可西里 更新时间:2023-11-01 12:38:17 25 4
gpt4 key购买 nike

我正在使用 Windows API 调用 FindFirstFileFindNextFile在目录中搜索与某个通配符字符串匹配的文件。例如,我可能想查找目录中的所有 XML 文件,因此我使用“*.xml”模式进行搜索。

我遇到的问题是,如果我正在搜索 3 个字母的扩展名,并且文件的扩展名以该 3 个字母的扩展名开头,即使扩展名包含更多内容,它也会被我的搜索选中前 3 个字符之后的字符。例如,如果我的文件名为 somelongname.xmlaaaa,则搜索“*.xml”时会找到它。该文件的简称是 somelo~1.xml,与我的通配符字符串匹配。

我可以自己进行通配符匹配来解决这个问题,但大概 Windows API 能够比我更有效地做到这一点,而且我的代码会更简单。据我所知,没有办法强制这些函数忽略短名称。 Windows 是否公开了具有此功能的任何 API?

最佳答案

查看 FindFirstFileEx - 它有一个采用 FINDEX_INFO_LEVELS 枚举的 fInfoLevelId 参数:

typedef enum _FINDEX_INFO_LEVELS {
FindExInfoStandard,
FindExInfoBasic,
FindExInfoMaxInfoLevel
} FINDEX_INFO_LEVELS;

FindExInfoBasic

The FindFirstFileEx function does not query the short file name, improving overall enumeration speed. The data is returned in a WIN32_FIND_DATA structure, and the cAlternateFileName member is always a NULL string.

但是:

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP: This value is not supported until Windows Server 2008 R2 and Windows 7.

关于c++ - 是否有不搜索短文件名的 Windows FindFirstFile/FindNextFile API 的替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8070224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com