Carbon equivalent of Windows API FindFirstFile function

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

  1. macrumors newbie

    Joined:
    Oct 15, 2010
    #1
    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

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #2
    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:
    Here
     
  3. thread starter macrumors newbie

    Joined:
    Oct 15, 2010
    #3
    Thanks I'll check it out.
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    Since FindFirstFile is primarily a wildcard pattern-matcher, a similar function in Mac OS X is glob().
    http://developer.apple.com/library/mac/#DOCUMENTATION/Darwin/Reference/ManPages/man3/glob.3.html

    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:
    http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx

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

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

    Source: http://msdn.microsoft.com/en-us/library/aa364428.aspx
     

Share This Page