开发者

How to check for existence of a file which does not have a specific name? (In an iPhone cocoa app)

开发者 https://www.devze.com 2023-04-03 03:10 出处:网络
I am currently able to periodica开发者_运维知识库lly monitor the existence of a particular file in a particular folder using NSTimer and NSFileManager. However, how will I go about checking the existe

I am currently able to periodica开发者_运维知识库lly monitor the existence of a particular file in a particular folder using NSTimer and NSFileManager. However, how will I go about checking the existence of a file as long as its title contains the text say, "MobileSafari", instead of the specific file name?

Any help is much appreciated!


Use NSMetaDataQuery. The predicate can use @"kMDItemFSName contains[c] %@" to find the files containing that string in their names. The searchScopes is an array of one or more strings with names of directories.

You should set up observer methods, i.e. register observers with [NSNotificationCenter defaultCenter] (in your class that launches the query) for the notifications NSMetadataQueryGatheringProgressNotification and NSMetadataQueryDidFinishGatheringNotification.

The former allows you to show the progress or to fetch the new results and display them. The latter indicates the query finished gathering, so you can stop the query and check [query resultCount] and [query results].

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号