5 * Created by Chris Taylor on Tue Jun 22 2004.
20 extern void macify_posix_path(char *posix_path, char *mac_path);
22 #include <CoreServices/CoreServices.h>
25 // Gets the names of matching files and the number of matching files.
26 int FindFiles(char *search_str, int max_matches, char **names)
32 ItemCount num_found = 0;
37 for (path_len = 0; *search_str && *search_str != '*'; path_len ++)
38 path[path_len] = *search_str++;
40 if (*search_str == '*')
44 // Convert the search directory to an FSRef in a way that OS 9 can handle
49 macify_posix_path(path, path);
50 CopyCStringToPascal(path, pascalPath);
51 if (FSMakeFSSpec(0, 0, pascalPath, &parentSpec) != noErr)
53 if (FSpMakeFSRef(&parentSpec, &parent) != noErr)
57 // "This function, though available through Carbon on Mac OS 8 and 9, is only implemented on Mac OS X."
58 if ((myErr = FSPathMakeRef((unsigned char const *) (path_len? path : "."), &parent, NULL)) != noErr)
61 if (FSRefMakePath(&parent, (unsigned char *) path, _MAX_PATH) != noErr) // Get the full path, to get the length
63 path_len = strlen(path)
69 if (FSOpenIterator(&parent, kFSIterateFlat, &iterator) != noErr)
72 MALLOC(refs, FSRef, max_matches);
75 ItemCount num_new_files;
77 myErr = FSGetCatalogInfoBulk(iterator, max_matches, &num_new_files, NULL, kFSCatInfoNone, NULL, refs, NULL, NULL);
79 for (i = 0; i < num_new_files; i++) {
80 char *p = path + path_len;
83 FSRefMakePath (refs + i, (unsigned char *) path, 255);
84 for (filename = p; *filename && strnicmp(filename, search_str, strlen(search_str)); filename++) {}
87 strncpy(*names, p, 12);
92 } while (myErr == noErr && num_found < max_matches);
95 if (FSCloseIterator(iterator) != noErr)