有没有到Windows用FindFirstFile / FindNextFile API不搜索短文件名的方法吗? [英] Is there an alternative to the Windows FindFirstFile/FindNextFile API that doesn't search short file names?

查看:442
本文介绍了有没有到Windows用FindFirstFile / FindNextFile API不搜索短文件名的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Windows API调用<一个href=\"http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCQQFjAA&url=http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418%28v=vs.85%29.aspx&ei=kci6TtGwKqHq2QWa1ajCBw&usg=AFQjCNEZdeD7Rk_PkGmVQosMyhgQ1lO16w&sig2=XjQK3PSs7WVDzh2O8E82sw\">FindFirstFile和<一个href=\"http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&sqi=2&ved=0CBoQFjAA&url=http://msdn.microsoft.com/en-us/library/windows/desktop/aa364428%28v=vs.85%29.aspx&ei=38i6Tp-6EYGU2AWuirnDBw&usg=AFQjCNG-eZr5AIhnTwM8nxgFow9m1AUReg&sig2=eDfRsNM5RXQn909ihJFNeg\">FindNextFile搜索匹配目录中的某个通配符字符串的文件。例如,我可能想查找目录中的所有XML文件,所以我搜索使用模式*的.xml。

I'm using the Windows API calls FindFirstFile and FindNextFile to search for files matching a certain wildcard string in a directory. For example, I might want to find all XML files in a directory, and so I search using the pattern "*.xml".

我运行到,如果我在寻找一个3个字母的扩展名,文件的扩展名与3个字母的扩展启动时,它会得到我的搜索拿起问题,即使延长含有较多那些最初的3。例如后面的​​字符,如果我的文件被命名为somelongname.xmlaaaa,这将得到*的.xml拾起搜索。该文件的短名称是somelo〜1.XML,这我通配符的字符串匹配。

I'm running into the problem that if I'm searching for a 3-letter extension, and a file's extension starts with that 3-letter extension, it will get picked up by my search, even if the extension contains more characters after those first 3. For example, if my file is named somelongname.xmlaaaa, this will get picked up by the search for "*.xml". The short name of that file is somelo~1.xml, which matches my wildcard string.

我可以做我自己的通配符匹配来解决这个问题,但presumably一个Windows API将能够比我和我的code会更简单更有效地做到这一点。至于我可以告诉大家没有办法迫使这些函数忽略短名称。是否有任何API使用这一功能的Windows暴露了?

I could do my own wildcard matching to get around this problem, but presumably a Windows API would be able to do this more efficiently than I could, and my code would be simpler. As far as I can tell there isn't a way to force these functions to ignore short names. Is there any API Windows exposes with this functionality?

推荐答案

不幸的是,在他的回答中发现的文档JoeFish原来是有点误导。搜索仍然会发现匹配的短名称,即使你在FindExInfoBasic传递文件。它只是将不包括在WIN32_FIND_DATA结构的cAlternateFileName成员短文件名。

Unfortunately, the documentation JoeFish found in his answer turns out to be a little misleading. The search will still find files that match the short name, even if you pass in FindExInfoBasic. It just won't include the short file name in the cAlternateFileName member of the WIN32_FIND_DATA structure.

我也不过发现有一个Windows函数的 PathMatchSpec 会做同样的通配符匹配针对提供的字符串。所以,我可以添加第二个步骤,我的搜索​​是验证长期名字模式匹配。它甚至可以在Windows XP中。

I did however find that there's a Windows function PathMatchSpec that will do the same wildcard matching against a supplied string. So, I was able to add a second step to my searching that verifies that the long name matches the pattern. It's even available in Windows XP.

这篇关于有没有到Windows用FindFirstFile / FindNextFile API不搜索短文件名的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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