I have a folder / Documents / Images, in this folder there are several other folders named for several years, in these folders I have images. I want to delete everything from the image folder (including folders and images in these folders).
I tried several code snippets but none of them delete folders
my method:
- (void) clearCache:(NSString *) folderName{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [paths objectAtIndex:0]; NSFileManager *fm = [NSFileManager defaultManager]; NSString *directory = [documentsDirectoryPath stringByAppendingPathComponent:folderName]; NSLog(@"Removing items at path: %@",directory); NSError *error = nil; BOOL succes = [fm removeItemAtPath:directory error:&error];
}
source share