1

How to check file without any case sensitivity is available or not in the current fileManager path directory? In current code lower case or higher case for file name string is important.

    - (BOOL) findFile{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSFileManager * fileManager = [NSFileManager new];
    NSArray * subpaths = [fileManager subpathsAtPath:[paths objectAtIndex:0]];
    NSString *myfilePath=nil;
    if([subpaths count]!=0)
        myfilePath=[subpaths objectAtIndex:0];
    if([myfilePath isEqualToString:@"FileName.png"] && myfilePath!=nil){
        myfilePath=[NSString stringWithFormat:@"%@/%@",[paths objectAtIndex:0],myfilePath];
        return TRUE;
    }
    else
        return FALSE;
}
Vahid Dianat
  • 53
  • 1
  • 9
  • 2
    Putting both at uppercase could do the trick. `if ([[myfilePath upperCase] isEqualToString:[@"FileName.png" upperCase]])`?, or instead of `isEqualToString:`, you could use `caseInsensitiveCompare:` – Larme Aug 02 '16 at 08:30
  • 1
    Good. I am going to use caseInsensitiveCompare. Useful answer. Thanks – Vahid Dianat Aug 02 '16 at 08:36
  • Possible duplicate of [Case insensitive comparison NSString](http://stackoverflow.com/questions/2582306/case-insensitive-comparison-nsstring) – Larme Aug 02 '16 at 08:59

0 Answers0