/**
   * @param n Node to populate
   * @param path Path to populate
   * @param depth Depth of iteration (0 = 1st level of nesting, 1 = 2 level of nesting, etc)
   */
  private void populateNode(DirectoryAdapter.Node n, String path, int depth) {
    if (path == null) {
      // We're on the storage list
      String storages[] = Util.getMediaDirectories();
      for (String storage : storages) {
        File f = new File(storage);
        DirectoryAdapter.Node child = new DirectoryAdapter.Node(f.getName(), getVisibleName(f));
        child.isFile = false;
        this.populateNode(child, storage, 0);
        n.addChildNode(child);
      }
      return;
    }

    File file = new File(path);
    if (!file.exists() || !file.isDirectory()) return;

    ArrayList<String> files = new ArrayList<String>();
    LibVLC.nativeReadDirectory(path, files);
    StringBuilder sb = new StringBuilder(100);
    /* If no sub-directories or I/O error don't crash */
    if (files == null || files.size() < 1) {
      // return
    } else {
      for (int i = 0; i < files.size(); i++) {
        String filename = files.get(i);
        /* Avoid infinite loop */
        if (filename.equals(".") || filename.equals("..") || filename.startsWith(".")) continue;

        DirectoryAdapter.Node nss = new DirectoryAdapter.Node(filename);
        nss.isFile = false;
        sb.append(path);
        sb.append("/");
        sb.append(filename);
        String newPath = sb.toString();
        sb.setLength(0);

        // Don't try to go beyond depth 10 as a safety measure.
        if (LibVLC.nativeIsPathDirectory(newPath) && depth < 10) {
          ArrayList<String> files_int = new ArrayList<String>();
          LibVLC.nativeReadDirectory(newPath, files_int);
          if (files_int.size() < 8) {
              /* Optimisation: If there are more than 8
              sub-folders, don't scan each one, otherwise
              when scaled it is very slow to load */
            String mCurrentDir_old = mCurrentDir;
            mCurrentDir = path;
            this.populateNode(nss, newPath, depth + 1);
            mCurrentDir = mCurrentDir_old;
          }
        } else {
          if (acceptedPath(newPath)) nss.setIsFile();
          else continue;
        }

        n.addChildNode(nss);
      }
      Collections.sort(n.children);
    }

    DirectoryAdapter.Node up = new DirectoryAdapter.Node("..");
    n.children.add(0, up);
  }