public void iterateThruFolder(String path){
  File root=new File(path);
  File[] list=root.listFiles();
  if (list == null) {
    return;
  }
  for (  File f : list) {
    if (f.isDirectory()) {
      iterateThruFolder(f.getAbsolutePath());
      if (!subdirectoriesList.contains(f.getPath())) {
        subdirectoriesList.add(f.getPath());
      }
    }
  }
}

public void iterateThruFolder ( String path ) { File root = new File ( path ) ; File [ ] list = root . listFiles ( ) ; if ( list == null ) { return ; } for ( File f : list ) { if ( f . isDirectory ( ) ) { iterateThruFolder ( f . getAbsolutePath ( ) ) ; if ( ! subdirectoriesList . contains ( f . getPath ( ) ) ) { subdirectoriesList . add ( f . getPath ( ) ) ; } } } }
this method goes through a folder recursively and saves all its subdirectories to an arraylist ( subdirectorieslist ) .
