简体   繁体   English

NSFileManager应用程序文件夹-iOS

[英]NSFileManager application folders - ios

I want to create 2 folders: "Images" and "Text", to download image type files to "Image" folder, and "text" type to "Text" folder. 我想创建2个文件夹:“图像”和“文本”,将图像类型文件下载到“图像”文件夹,将“文本”类型下载到“文本”文件夹。 Questions: 1)Where and how i should create them? 问题:1)我应该在哪里以及如何创建它们? 2)How to get path for this created folders? 2)如何获取此创建文件夹的路径? Please write some short example, or give url to similar example. 请写一些简短的例子,或给类似例子提供url。

Try this: (your can learn more about NSFileManager from Apple's docs) 尝试以下操作:(您可以从Apple的文档中了解有关NSFileManager的更多信息)

NSError *error = nil;
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];  //this get you to the root of your app's
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"yourfoldername"];  

if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath])  //Optionally check if folder already hasn't existed.
{
[[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:NO attributes:nil error:&error];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM