Deleting all the files in the iPhone sandbox (documents folder)?

前端 未结 7 2063
清歌不尽
清歌不尽 2020-11-28 05:50

Is there an easy way to delete all the files(images) I saved in the documents folder of the app?

相关标签:
7条回答
  • 2020-11-28 06:55
     NSFileManager *fileMgr = [[[NSFileManager alloc] init] autorelease];
    NSError *error = nil;
    NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error];
     if (error == nil) {
       for (NSString *path in directoryContents) {
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:path];
        BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error];
        if (!removeSuccess) {
            // Error handling
            ...
        }
    }
    } else {
     // Error handling
    ...
    }
    
    0 讨论(0)
提交回复
热议问题