gpt4 book ai didi

iphone - 在 NSDocumentDirectory 中删除

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:13 24 4
gpt4 key购买 nike

我这样保存在 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 的所有图像。

谢谢

最佳答案

试试这个,只需复制这段代码,您的名为 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];
}
}
}

关于iphone - 在 NSDocumentDirectory 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11450054/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com