How to delete a file

- by

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).



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site witout any pesky ads! More details here.

Add your voice!

This site uses Akismet to reduce spam. Learn how your comment data is processed.