Checking NSString path is a Directory or File in iOS.

Total Post:27

 840  View(s)
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. Post:214

    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];
          NSLog(@"Directory Path: %@", dirPath);

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



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