Carbon equivalent of Windows API FindFirstFile function

Discussion in 'Mac Programming' started by MACaveli7, Nov 9, 2010.

  1. macrumors newbie

    Oct 15, 2010
    As the title dictates i am trying to locate the equivalent function to the Windows API function

    HANDLE WINAPI FindFirstFile(
    __in LPCTSTR lpFileName,
    __out LPWIN32_FIND_DATA lpFindFileData

    It takes a filename and writes the data to the second parameter, the files it returns are in alphabetical order.

    I have taken a look at the File Manager system, I don't see anything there that can do that for me.
  2. macrumors 603


    Aug 2, 2002
    Cork, Ireland.
    I guess the closest equivalent is FSGetCatalogInfoBulk() (see here), but I should warn you it's nowhere near as simple as FindFirstFile() - the Carbon file APIs are not easy to pick up and use!! (The Cocoa equivalent would be a trivial few lines of code).

    There's some sample code in the FSMegaInfo project:
  3. thread starter macrumors newbie

    Oct 15, 2010
  4. macrumors 604

    Aug 9, 2009
    Since FindFirstFile is primarily a wildcard pattern-matcher, a similar function in Mac OS X is glob().

    It's a BSD C function and performs pattern-matching like the shell, which means it uses slash-delimited pathnames, not colon-delimited ones. I assume this is what is desired.

    Another way of finding files is with a metadata query.
    Google search terms:
    mac os spotlight metadata query

    BTW, this MSDN reference:

    says this about "alphabetical order":
    "... This is because FindFirstFile does no sorting of the search results."​
  5. macrumors newbie

    Jun 4, 2010
    And the FindNextFile() documentation expands on the above (emphasis mine):


Share This Page