我用这样的东西保存了所有文件
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.
Run Code Online (Sandbox Code Playgroud)
所有这些文件都以.plist扩展名保存.同一目录包含几个JPG和PNG文件.
现在,如何检索该目录中所有.plist文件的列表?
谢谢你的帮助.
您可以使用以下调用来获取给定路径中所有文件的列表,然后遍历列表过滤任何扩展名为.plist的文件:
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:docsDir];
NSString *file;
while (file = [dirEnum nextObject]) {
if ([[file pathExtension] isEqualToString: @"plist"]) {
// process the document
}
}
Run Code Online (Sandbox Code Playgroud)