0

Scenario: My Assets directory - Assets/folder1; Assets/folder2; and so on. With files in folder1 and other folders, such as Asssets/folder1/file1, and others, Asssets/folder/somefile1, and others.

I want the code to access names of only folder names from Assets folder i.e., as a list.

  • folder1
  • folder2
  • and so on.

    new File("file:///android_asset/").listFiles(); new File("file:///android_asset/").list(); Both of the above statements return null. what would be the path for Assets folder? Thanks!

Johnny
  • 282
  • 1
  • 15
  • ` new File("file:///android_asset/").listFiles(); new File("file:///android_asset/").list(); ` Both of the above statements return null. what would be the path for Assets folder? – Johnny Jul 27 '15 at 18:03

2 Answers2

0

You can use File.listFiles() to get all files in a given directory (including sub-directories). From these you can get the names.

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58
0

Try following

public static getDirNames(String sDir){
List<String> listDir;
  File[] faFiles = new File(sDir).listFiles();
  for(File file: faFiles)
   {
       if(file.isDirectory())
    {
      getDirNames(file.getAbsolutePath());
    listDir.add(file.getName());
    }
  }
  • Thanks for the reply! What would be the path for Assets folder! – Johnny Jul 27 '15 at 15:43
  • please refer http://stackoverflow.com/questions/4820816/how-to-get-uri-from-an-asset-file –  Jul 28 '15 at 05:33
  • It says **There is no "absolute path for a file existing in the asset folder". The content of your project's assets/ folder are packaged in the APK file.** So there's no way to access folder names from Assets folder at runtime? – Johnny Jul 28 '15 at 07:54