如何在我的iPhone应用程序的documents目录内创建目录?
问题描述:
我想将文件存储在documents目录内的特定目录中,这样我就可以遍历所有这些文件并显示给用户选择。
I would like to store files in a specific directory inside the documents directory, so that I can iterate over all these files and show them to the user for selection. Is that possible?
答
是的,您可以这样做:
NSString *rootString = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
self.root = [rootString stringByAppendingPathComponent:@"DirectoryName"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:root isDirectory:YES] == NO)
{
[fileManager createDirectoryAtPath:root attributes:nil];
}
对于检索,您可以执行以下操作:
And For retrieving you can do this:
NSError *error;
NSArray *files = [fileManager contentsOfDirectoryAtPath:root error:&error];
希望这会有所帮助,
谢谢,
Madhup
Thanks, Madhup