title: Check the attribute of items in a directory in Objective-C
body: <p>I have made this little code to check how many subdirectories are in a given directory. It checks only the first level, is there anyway I can make it simplier? I have added comments, maybe easier to understand my intention. Thank you!</p>
  
  <blockquote>
  <pre><code>    #import &lt; Foundation/Foundation.h &gt;            
              int main (int argc, const char * argv[]){
  </code></pre>
  </blockquote>
  
  <pre><code>  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  
  
  
  // insert code here...
  NSFileManager *filemgr;
  NSMutableArray *listOfFiles;
  NSDictionary *listOfFolders;
  NSDictionary *controllDir;
  int i, count;
  NSString *myPath;
  
  filemgr = [NSFileManager defaultManager];
  
  myPath = @"/";
  
  // list the files in the given directory (myPath)
  
  listOfFiles = [filemgr directoryContentsAtPath: myPath];
  
  // count the number of elements in the array
  count = [listOfFiles count];
  
  // check them one by one
  for (i = 0; i &lt; count; i++)
  {
      // I need the full path
     NSString *filePath =[NSString stringWithFormat:@"%@/%@", myPath, [listOfFiles objectAtIndex: i]];
  
      // add every item with its attributes
      listOfFolders = [filemgr attributesOfItemAtPath:filePath error:NULL];
  
      // to avoid typo get the attribute and create a string
      controllDir = [filemgr attributesOfItemAtPath:@"/" error:NULL];
      NSString *toCheck = [NSString stringWithFormat:@"%@", [controllDir objectForKey:NSFileType]];   
  
      // the folder elements one by one
      NSString *fileType = [NSString stringWithFormat:@"%@", [listOfFolders objectForKey:NSFileType]];    
  
  
      if([toCheck isEqualToString:fileType])
          {
              NSLog(@"NAME: %@  TYPE: %@" ,[listOfFiles objectAtIndex:i],[listOfFolders objectForKey:NSFileType]);
          }                
  }            
  
  [pool drain];
  return 0;
  }
  </code></pre>