I am trying to get a list of directories in a user's iCloud folder. I developed how to search for special file types (e.g. txt files) and it works great:
NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; _query = query;
However, now I am trying to get only directories. I have read the docs regarding NSPredicate , but I donβt know how to look for directories. Probably NSPredicate is not for this? I can check if there is anything in this directory:
BOOL isDir; BOOL exists = [fm fileExistsAtPath:path isDirectory:&isDir]; if (exists) { if (isDir) { } }
But how to apply this to NSMetadataQuery, I have no idea. I would be grateful for any help I can get.
EDIT:
I changed the predicate to [NSPredicate predicateWithFormat:@"%K.pathExtension = ''", NSMetadataItemFSNameKey];
Then I determine when the request is completed as follows:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:query]; [query startQuery]; - (void)queryDidFinishGathering:(NSNotification *)notification { NSMetadataQuery *query = [notification object]; [query disableUpdates];
And finally, I do the counting, but it will always give me 0, however I have several directories in the cloud (I checked this through Lion and the Mobile Documents folder, for example, I have documents / myTXT, etc.). It is very strange. If I do a text file count, it will give me 4, since I have 4 txt files. Therefore, I think my directories are not counted:
- (void)loadData:(NSMetadataQuery *)query { NSLog(@"Query count %i", [query resultCount]); ...