开发者

check if file exist

开发者 https://www.devze.com 2023-03-21 17:47 出处:网络
i want to check a folder.if i found \"test.jpeg\" in \"path\" if it \'s true i do nothing but if it false i have to download this picture like that

i want to check a folder.if i found "test.jpeg" in "path" if it 's true i do nothing but if it false i have to download this picture like that

UIIm开发者_开发问答age *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[dico objectForKey:@"photo"]]]];
nomPhoto = [[cell.pseudo text]stringByReplacingOccurrencesOfString:@"\n" withString:@""];;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *document = [paths objectAtIndex:0];
filename = [NSString stringWithFormat:@"%@/%@.jpeg",document,nomPhoto];

NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 0.1f)];//1.0f = 100% quality

[data2 writeToFile:filename atomically:YES];

EDIT: i try this but don't work. the path is good

NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* pict =  [documentsPath stringByAppendingPathComponent :@"portos"]; 


BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:pict];

if (fileExists)
{
    NSLog(@"file ok");
}else {
    NSLog(@"file ko");
}

thx


Its already answered here.

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];


If the file specified doesn't exist the CGImage property of UIImage will be nil.

if (image.CGImage) NSLog(@"file ok");
else NSLog(@"file ko");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号