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
UIImage *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
In Python, you can check whether certain files or directories exist using the isfile() and isdir() methods, respectively. However, if you use isfile() to check if a certain directory exists, the method will return False. Likewise, if you use if isdir() to check whether a certain file exists, the method returns False.
When checking if a file exists, the most commonly used FILE operators are -e and -f . The first one will check whether a file exists regardless of the type, while the second one will return true only if the FILE is a regular file (not a directory or a device).
html file exists in the current folder, you can write the following code: const fs = require("fs"); const path = "./index. html"; fs. exists(path, function (isExist) { if (isExist) { console.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With