简体   繁体   中英

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. Questions: 1)Where and how i should create them? 2)How to get path for this created folders? Please write some short example, or give url to similar example.

Try this: (your can learn more about NSFileManager from Apple's docs)

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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