Q:

How can I list all sub dir in my internal storage?

I want to have a list of all my sub dir in internal storage I already created in other activity.
I want to do something like this getFilesDir().listFiles(); but this one is for files in root and I want to list dirs to do this subDir = getDir("nameOfDir", MODE_PRIVATE); and this last code work but with "static" names. I want to do this dynamically.

A:

This is printing all the file names and directory names using recursion:
public static void main(String[] args) throws IOException, URISyntaxException{
    getFiles("your/path");

}
public static void getFiles(String path){
    File folder = new File(path);
    File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {
      if (listOfFiles[i].isFile()) {
        System.out.println("File " + listOfFiles[i].getName());
      } else if (listOfFiles[i].isDirectory()) {
        System.out.println("Directory " + listOfFiles[i].getName());
          getFiles(listOfFiles[i].getPath());
      }
    }
}

