title: How to check if a directory exists in Objective-C
body: <p>I guess this is a beginner's problem, but I was trying to check if a directory exists in my Documents folder on the iPhone. I read the documentation and came up with this code which unfortunately crashed with EXC_BAD_ACCESS in the BOOL fileExists line:</p>
  
  <pre><code> -(void)checkIfDirectoryAlreadyExists:(NSString *)name
  {
      NSFileManager *fileManager = [[NSFileManager alloc] init];
  
      NSString *path = [[self documentsDirectory] stringByAppendingPathComponent:name];
  
      BOOL fileExists = [fileManager fileExistsAtPath:path isDirectory:YES];
  
      if (fileExists)
      {
          NSLog(@"Folder already exists...");
      }
  
  }
  </code></pre>
  
  <p>I don't understand what I've done wrong? It looks all perfect to me and it certainly complies with the docs, not? Any revelations as to where I went wrong would be highly appreciated! Thanks.</p>
  
  <p>UPDATED:</p>
  
  <p>Still not working...</p>
  
  <pre><code>  -(void)checkIfDirectoryAlreadyExists:(NSString *)name
  {
      NSFileManager *fileManager = [[NSFileManager alloc] init];
  
      NSString *path = [[self documentsDirectory] stringByAppendingPathComponent:name];
  
      BOOL isDir;
      BOOL fileExists = [fileManager fileExistsAtPath:path isDirectory:&amp;isDir];
  
      if (fileExists)
      {
  
  
          if (isDir) {
  
              NSLog(@"Folder already exists...");
  
          }
  
      }
  
  }
  </code></pre>