CHECKING NSSTRING PATH IS A DIRECTORY OR FILE IN IOS.

Glen Martin

Total Post:27

Points:191
Posted by  Glen Martin
 630  View(s)
Ratings:
Rate this:

In our iPhone application I have a nsstring which can be a path of any location or file.

Now, I want to check that string(path) is locating a file or folder/director.

Is this possible in Cocoa to check the string path for file or directory, then please provide me the code or tell me the method.
Thank you.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Checking NSString path is a Directory or File in iOS.

    For checking existence of file or directory you can use NSFileManager:
    [[NSFileManager defaultManager]fileExistsAtPath:path_name isDirectory:&directoryFlag];
    Here we are providing complete example:

    NSString *dirPath = @"/Album/";
    BOOL check;
    NSDirectoryEnumerator *enum = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];
    while((dirPath = [enum nextObject])){
       [[NSFileManager defaultManager] fileExistsAtPath:dirPath isDirectory:&check];
       if(check){
          NSLog(@"Directory Path: %@", dirPath);
       }
    }

      Modified On Jan-04-2016 10:31:17 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!