remove images from NSHomeDirectory() in iphone
Hi i am saving images like this:
[UIImagePNGRepresentation(image) writeToFile:[self findUniqueSavePath] atomically:YES];
// Show the current contents of the documents folder
CFShow([[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingString:@"/Documents"]]);
- 开发者_JAVA技巧(NSString *) findUniqueSavePath
{
int i = 1;
NSString *path;
do
{
// iterate until a name does not match an existing file
path = [NSString stringWithFormat:@"%@/Documents/IMAGE-%d.PNG", NSHomeDirectory(), i++];
} while ([[NSFileManager defaultManager] fileExistsAtPath:path]);
[classObj updateimage];
return path;
}
I want to remove images when the new image write in the document.
you can use this code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path=[documentsDirectory stringByAppendingPathComponent:@"image.png"];
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
精彩评论