Create a new folder and delete folders inside the Program Document folder

Source: Internet
Author: User

//

Viewcontroller.m

12.18.04 Creating a folder in document

//

Created by Zhang Kaize on 15/12/18.

COPYRIGHT©2015 year Rytong_zkz. All rights reserved.

//

#import "ViewController.h"

@interface Viewcontroller ()

@property (nonatomic,strong) nsfilemanager *filemanager;//File Manager

@property (nonatomic,copy) nsstring *createpath;//folder Imge

@property (nonatomic,copy) nsstring *createdir;//folder Messagequeueimage

-(Ibaction) Deleteclick: (UIButton *) sender;

@end

@implementation Viewcontroller

Create a File Manager

-(Nsfilemanager *) FileManager

{

if (_filemanager = = nil) {

_filemanager = [Nsfilemanager Defaultmanager];

}

return _filemanager;

}

Create a path----Create a folder in document Imge

-(NSString *) Createpath

{

if (_createpath = = nil) {

NSString *pathdocuments = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) OBJECTATINDEX:0];

NSLog (@ "pathdocuments =%@", pathdocuments);

_createpath = [NSString stringwithformat:@ "%@/image", pathdocuments];

}

return _createpath;

}

Create a path----Create a folder in document Messagequeueimage

-(NSString *) Createdir

{

if (_createdir = = nil) {

NSString *pathdocuments = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) OBJECTATINDEX:0];

NSLog (@ "pathdocuments =%@", pathdocuments);

_createdir = [NSString stringwithformat:@ "%@/messagequeueimage", pathdocuments];

}

return _createdir;

}

-(void) Viewdidload {

[Super Viewdidload];

Determines whether the folder exists, if it does not exist, creates

if (![ Self.filemanager FileExistsAtPath:self.createPath]) {

[Self.filemanager createDirectoryAtPath:self.createPath withintermediatedirectories:yes Attributes:nil Error:nil];

Create File Messagequeueimage

[Self.filemanager createDirectoryAtPath:self.createDir withintermediatedirectories:yes Attributes:nil Error:nil];

Writes the string to the newly created file inside.

NSString * ss = @ "ios";

NSString * Path = [NSString stringwithformat:@ "%@/ios.text", Self.createpath];

BOOL B = [ss Writetofile:path atomically:yes encoding:nsutf8stringencoding Error:nil];

if (b) {

NSLog (@ "write string OK");

}else{

NSLog (@ "write String Faluse");

}

} else {

NSLog (@ "Filedir is exists.");

}

}

Delete the Imge folder in document

-(Ibaction) Deleteclick: (UIButton *) Sender {

if ([Self.filemanager FileExistsAtPath:self.createPath]) {

Nserror * ERROR;

BOOL B = [Self.filemanager RemoveItemAtPath:self.createPath error:&error];

if (b) {

NSLog (@ "delete success");

}

else{

NSLog (@ "Delete Faulse");

}

}

}

@end

Create a new folder and delete folders inside the Program Document folder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.