Is there an easy way to delete all the files(images) I saved in the documents folder of the app?
Go to the "Files" app and click "On My iPhone/iPad". Step 2. Find the file or folder you want to delete. If the files or folders are saved in iCloud but not in the internal storage, you need to remove these unwanted items from the iCloud Drive.
Press the Shift key to select multiple files or folders. In the confirmation pop-up window, select Delete to delete your files permanently from the cloud.
NSFileManager *fileMgr = [[[NSFileManager alloc] init] autorelease]; NSError *error = nil; NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]; if (error == nil) { for (NSString *path in directoryContents) { NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:path]; BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error]; if (!removeSuccess) { // Error handling ... } } } else { // Error handling ... }
Code did not work with IOS 7 and Xcode 5 so edited to work with my app. Big credits to @Ole Begemann and @pablasso.
-(void)EmptySandbox { NSFileManager *fileMgr = [[NSFileManager alloc] init]; NSError *error = nil; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSArray *files = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:nil]; while (files.count > 0) { NSString *documentsDirectory = [paths objectAtIndex:0]; NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]; if (error == nil) { for (NSString *path in directoryContents) { NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:path]; BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error]; files = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:nil]; if (!removeSuccess) { // Error } } } else { // Error } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With