How to delete files from a folder which is placed in documents folder

馋奶兔 提交于 2019-12-13 08:04:04

问题


I want to delete the files which are placed in a folder(inside documents folder) of documents directory. I just listed or displayed all those files on the table view , can anybody tell me how can i do this using commitEditingStyle: method. Please help me how can i achieve this.Thanks in advance.


回答1:


You can use the below code to delete the file from document directory:

NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documents= [documentsDirectory stringByAppendingPathComponent:@"YourFolder"];
NSString *filePath = [documents stringByAppendingPathComponent:@"file2.txt"];
[fileMgr removeItemAtPath:filePath error:&error]


来源:https://stackoverflow.com/questions/14473858/how-to-delete-files-from-a-folder-which-is-placed-in-documents-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!