PDA

View Full Version : Carbon equivalent of Windows API FindFirstFile function




MACaveli7
Nov 9, 2010, 04:15 AM
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.



whooleytoo
Nov 9, 2010, 06:05 AM
I guess the closest equivalent is FSGetCatalogInfoBulk() (see here (http://developer.apple.com/library/mac/#documentation/Carbon/Reference/File_Manager/Reference/reference.html)), 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 (http://developer.apple.com/library/mac/#samplecode/FSMegaInfo/Listings/FileManager_c.html%23//apple_ref/doc/uid/DTS10004032-FileManager_c-DontLinkElementID_13)

MACaveli7
Nov 9, 2010, 07:53 AM
Thanks I'll check it out.

chown33
Nov 9, 2010, 11:27 AM
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."

javacool
Nov 11, 2010, 12:55 PM
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."

And the FindNextFile() documentation expands on the above (emphasis mine):


The order in which the search returns the files, such as alphabetical order, is not guaranteed, and is dependent on the file system. If the data must be sorted, the application must do the ordering after obtaining all the results.

[...]

The order in which this function returns the file names is dependent on the file system type. With the NTFS file system and CDFS file systems, the names are usually returned in alphabetical order. With FAT file systems, the names are usually returned in the order the files were written to the disk, which may or may not be in alphabetical order. However, as stated previously, these behaviors are not guaranteed.


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