开发者

iphone: how do I obtain a list of all files with a given extension on the app's document folder?

I have saved all my files using something like this

NSString *fileName = [NSString stringWithFormat:@"%@.plist", myName];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];

[myDict writeToFile:appFile atom开发者_StackOverflowically:YES])

//where myDic is a dictionary containing the value of all parameters I would like to save.

All these files were saved with the .plist extension. The same directory contains several JPG and PNG files.

Now, how do I retrieve the list of all .plist files on that directory?

thanks for any help.


you can use the following call to get a list of all files in a given path and then iterate through the list filtering any files with .plist extension:

NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:docsDir];

NSString *file;
while (file = [dirEnum nextObject]) {
    if ([[file pathExtension] isEqualToString: @"plist"]) {
        // process the document
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜