Cocoa - NSFileManager removeItemAtPath Not Working

前端 未结 6 613
再見小時候
再見小時候 2021-01-21 04:03

I am trying to delete a file, but somehow nsfilemanager will not allow me to do so. I do use the file in one line of code, but once that action has been ran, I want the file del

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 05:05

    First you need to pick the path for the document directory then you can delete the file. Only remove statement is not sufficient.

       NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
            NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    
        NSString *databaseFile = [documentsDirectoryPath stringByAppendingPathComponent:@"text.txt"];
    
        NSFileManager *fileManager = [NSFileManager defaultManager];
        [fileManager removeItemAtPath:databaseFile error:NULL];
    

    use this for solving your problem.

提交回复
热议问题