August 7, 2013 · 0 Comments
-(void) DeleteDocumentFiles{ // Path to the Documents directory NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([paths count] > 0) { NSError *error = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; // Print out the path to verify we are in the right place NSString *directory = [paths objectAtIndex:0]; NSLog(@"Directory: %@", directory); // For each file in the directory, create full path and delete the file for (NSString *file in [fileManager contentsOfDirectoryAtPath:directory error:&error]) { NSString *filePath = [directory stringByAppendingPathComponent:file]; NSLog(@"File : %@", filePath); BOOL fileDeleted = [fileManager removeItemAtPath:filePath error:&error]; if (fileDeleted != YES || error != nil) { // Deal with the error... } } } }