How to delete a file

Once you have a reference to the file in question you can call the removeItemAtPath method:

// get reference with path and filename
NSString *filePath = [[NSString alloc]initWithFormat:@"Documents/myFile.txt"];
NSString *deleteThis = [NSHomeDirectory()stringByAppendingPathComponent:filePath];
// now delete the file
[[NSFileManager defaultManager]removeItemAtPath:deleteThis error:nil];

This does not work with wildcards in the file name (for example *.jpg).





Leave a Reply