我以这种方式保存在NSDocumentDirectory中:
NSLog(@"%@", [info objectAtIndex:i]);
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask ,YES );
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]];
ALAssetRepresentation *rep = [[info objectAtIndex: i] defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[rep fullResolutionImage]];
//----resize the images
image = [self imageByScalingAndCroppingForSize:image toSize:CGSizeMake(256,256*image.size.height/image.size.width)];
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];我知道怎么删除NSDocumentDirectory里的所有图片。
但是我想知道如何删除所有名为oneSlotImages的图片。
谢谢
发布于 2012-07-12 18:59:37
试试这个,只需复制这段代码,你的名字为oneSlotImages的图像将从DocumentDirectory中删除,这很简单:
NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] error:NULL];
if([directoryContents count] > 0)
{
for (NSString *path in directoryContents)
{
NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:path];
NSRange r =[fullPath rangeOfString:@"oneSlotImages"];
if (r.location != NSNotFound || r.length == [@"oneSlotImages" length])
{
[[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
}
}
}发布于 2012-07-12 18:45:44
你看过NSFileManager的方法吗?也许像这样的东西在你所有的图像中调用一个循环。
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:NULL];发布于 2012-07-12 18:56:32
使用like,
NSArray *dirFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:strDirectoryPath error:nil];
NSArray *zipFiles = [dirFiles filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self CONTAINS[cd] %@", @"oneSlotImages"]];数组zipFiles包含我们过滤的所有文件的名称。因此,通过在循环中将文档目录的完整路径附加到文件名中,可以使数组中所有过滤的文件都具有完整的文件路径。然后,您可以使用循环并调用NSFileManager对象的方法,如下所示
[fileManager removeItemAtPath: strGeneratedFilePath error: &err];这将从目录中删除itm at路径。
通过这种方式,您可以过滤出包含oneSlotImages的文件名。因此,您可以选择删除这些文件。希望这对你有帮助。
https://stackoverflow.com/questions/11450054
复制相似问题