I am having a file called demo.png which is saved in the documents/test/ folder. 
Now I want to check whether the files exists at that particular path and I want to delete that file. How to check that can you please tell me ??
 NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
 NSString* foofile = [documentsPath stringByAppendingPathComponent:@"foo.html"];
 BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
 if (fileExists)    //Does file exist?
     {
    if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error])   //Delete it
    {
        NSLog(@"Delete file error: %@", error);
    }
   } 
                        if([[NSFileManager defaultManager] fileExistsAtPath:somePath])
     [[NSFileManager defaultManager] removeItemAtPath:somePath error:NULL]; 
This can be used to check if file exist at your path.
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