Skip to content

Instantly share code, notes, and snippets.

@SongJiaqiang
Created November 23, 2016 01:54
Show Gist options
  • Save SongJiaqiang/289d59204efb5fe3a293574a8cbc1c52 to your computer and use it in GitHub Desktop.
Save SongJiaqiang/289d59204efb5fe3a293574a8cbc1c52 to your computer and use it in GitHub Desktop.
delete file from document directory.
- (void)removeFile:(NSString *)filename
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:filename];
NSError *error;
BOOL success = [fileManager removeItemAtPath:filePath error:&error];
if (success) {
UIAlertView *removedSuccessFullyAlert = [[UIAlertView alloc] initWithTitle:@"Congratulations:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[removedSuccessFullyAlert show];
}
else
{
NSLog(@"Could not delete file -:%@ ",[error localizedDescription]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment