Introduction
in my project, i've to delete folder and it's content(s) so i tried with this accepted answer ClickHere
it works and i thought that the task is over but after deleting a whole folder(Directory)i see that the memory is still allocated but file doesn't exist.
here is my code to delete directory(folder).
-(BOOL)removeItem:(NSString*)name{
//name: is directory(folder)'s name
NSString*path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
path = [path stringByAppendingPathComponent:@"Normal"];
path = [path stringByAppendingPathComponent:name];
NSError* err;
NSArray* list = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:path error:&err];
if(err){
NSLog(@"\n##CONTENTS OF DIRECTORY ERROR:->\n%@",err.localizedDescription);
}
//if array's count is not zero(0) it means directory has files available.
if(list.count >= 1){
for(NSString* string in list){
[[NSFileManager defaultManager]removeItemAtPath:[path stringByAppendingPathComponent:string] error:&err];
if(err){
NSLog(@"\n##FOLDER IN FOLDER ERROR:->\n%@",err.localizedDescription);
}
}
[[NSFileManager defaultManager]removeItemAtPath:path error:&err];
return YES;
}else{
[[NSFileManager defaultManager]removeItemAtPath:path error:&err];
if (err) {
return NO;
}
return YES;
}
}
thanks in advance.