//
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