title: List of all folders and folders inside them for Dropbox
body: <p>Im adding a "move to folder" functionality to my app with dropbox support. Im trying to get all folders, and subfolders throughout the whole users dropbox. Heres the code i have right now that if logged, has the right order but is backwards</p>
  
  <pre><code>-(void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
  
      if (allFolders == nil) {
          allFolders = [[NSMutableArray alloc] init];
          [allFolders addObject:@"/"];
      }
  
      for (DBMetadata *fileMetadata in metadata.contents) {
  
          if ([fileMetadata isDirectory]) {
              NSArray *filePathComponents = [fileMetadata.path pathComponents];
              NSString *inFolder = [filePathComponents objectAtIndex:[filePathComponents count]-2];
              NSLog(@"file is in folder %@",inFolder);
              [allFolders insertObject:fileMetadata.filename atIndex:[allFolders indexOfObject:inFolder]];
              if ([metadata.contents count] &gt; 0) [[self restClient] loadMetadata:fileMetadata.path];
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>the issue with this is my <code>hViewFoldersViewController</code> also has to show all folders for the documents directory for the app, and i use a custom <code>NSObject</code> called Folder Item which stores all items path, name, and indent level for the table. if i use this method, i cannot get the path because al lFolders in inside the dropbox helper class, i can move it to the <code>viewcontroller</code> but the thing that is confusing me is getting the <code>objectAtIndex</code>. if i leave it to just adding objects, it will show all first level folders, then second, then third. i want it so if in dropbox you have a folder called "test 1" and then test 1 contained "test 2", then it shows test 1, then with more indent the test 2 folder and then other first directory folders.  and if i use my FolderItem in the array i cannot find the <code>objectAtIndex</code>. How can i get the index of the folders i need to insert then?</p>