Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MACaveli7

macrumors newbie
Original poster
Oct 15, 2010
23
0
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.
 
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
 
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."​
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.