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

前端 未结 7 2106
清歌不尽
清歌不尽 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
    ...
    }
    

提交回复
热议问题