views:

63

answers:

1

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 atomically: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.

+1  A: 

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
    }
}
Claus Broch
thanks. I thought there was a way of obtaining it at once, something as filtering with "*.plist"... anyway, thanks!
Digital Robot
You can get a list of all content by using directoryContentAtPath:error in one call, but you will still have to iterate through the list and filter it.
Claus Broch