ios – 如何获取NSDocumentDirectory中的directores列表?

ios – 如何获取NSDocumentDirectory中的directores列表?,第1张

概述我在NSDocumentDirectory中创建了一些目录 if (![tbxCreateFolder.text isEqualToString:@""]) {NSArray *arrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documen 我在NSdocumentDirectory中创建了一些目录

if (![tbxCreateFolder.text isEqualToString:@""]) {NSArray  *arrPaths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);Nsstring *documentsDirectoryStr = [arrPaths objectAtIndex:0]; // Get documents folderNsstring *dataPath = [documentsDirectoryStr stringByAppendingPathComponent:[Nsstring stringWithFormat:@"/%@",tbxCreateFolder.text]];if (![[NSfileManager defaultManager] fileExistsAtPath:dataPath]){    NSError* error;    if([[NSfileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectorIEs:NO attributes:nil error:&error]){        NSLog(@"success");        //Perfrom DB Insertation    }    else    {        NSLog(@"[%@] ERROR: attempting to write create MyFolder directory",[self class]);        NSAssert( FALSE,@"Failed to create directory maybe out of disk space?");    }}

}

现在我想获取我在文档文件夹中创建的目录列表,但响应是

NSArray *arrPaths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES);Nsstring *basePathString = ([arrPaths count] > 0) ? [arrPaths objectAtIndex:0] : nil;NSLog(@"dirContents %@",basePathString);

回应是:

/Users/amir/library/Application Support/iPhone Simulator/6.1/Applications/7003E8D5-CCBB-4E54-896B-F4BD2F4D2CB1/documents
解决方法 这是代码:

Nsstring *documentDirPath = [NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,YES) objectAtIndex:0];// create directory named "test"[[NSfileManager defaultManager] createDirectoryAtPath:[documentDirPath stringByAppendingPathComponent:@"test"] withIntermediateDirectorIEs:YES attributes:nil error:nil];// retrIEved all directorIEsNSLog(@"%@",[[NSfileManager defaultManager] contentsOfDirectoryAtPath:documentDirPath error:nil]); NSArray *paths = [[NSfileManager defaultManager] contentsOfDirectoryAtPath:documentDirPath error:nil]; BOol isDir = NO; for (Nsstring *path in paths) {     if ([fileManager fileExistsAtPath:path isDirectory:&isDir] && isDir) {         // path is directory     }}
总结

以上是内存溢出为你收集整理的ios – 如何获取NSDocumentDirectory中的directores列表?全部内容,希望文章能够帮你解决ios – 如何获取NSDocumentDirectory中的directores列表?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1074421.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存