Is there an alternative to the Windows FindFirstFile/FindNextFile API that doesn't search short file names?

后端 未结 2 1353
抹茶落季
抹茶落季 2020-12-17 18:36

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

相关标签:
2条回答
  • 2020-12-17 19:02

    Check out FindFirstFileEx - it has a fInfoLevelId parameter that takes a FINDEX_INFO_LEVELS enumeration:

    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.

    However:

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

    0 讨论(0)
  • 2020-12-17 19:08

    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.

    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.

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