Delete multiple files from iphone document folder?

My Iphone application saves photos in a folder with documents. After use, I want to delete this entire folder with the file form. I know how to delete one file at a time using the path

if ([fileMgr removeItemAtPath:filePath error:&error] != YES) NSLog(@"Unable to delete file: %@", [error localizedDescription]); 

but I want to delete the whole file in one go. All my files are in .png format. I tried * .png but did not work.

+4
source share
1 answer
 /* dir: the directory where your files are */ NSFileManager *fm = [NSFileManager defaultManager]; NSError *error = nil; NSArray *items = [fm contentsOfDirectoryAtPath:dir error:&error]; if (error) { /* ... */ } /* delete png files */ for (NSString *item in items) { if ([[item pathExtension] isEqualToString:@"png"]) { NSString *path = [dir stringByAppendingPathComponent:item]; [fm removeItemAtPath:path error:&error]; if (error) { /* ... */ } } } 
+4
source

All Articles