Search code examples
androidsd-card

How to get full path of a folder from sdcard?


I want to get all folders and sub folders of a sdcard. For example, I created a folder name tempfolder. If I want to get the full path of tempfolder, like mnt/sdcard/folder/tempfolder. If i don't know where the folder is stored in sdcard, but i know the name of a folder.

Is it possible to get the full path of a folder based on folder name. If any one knows the solution, please help me.


Solution

  • You can do the next thing:

        //get the path of the sdcard and enter all the files to an array file
            File[] file = Environment.getExternalStorageDirectory().listFiles();  
    
    
            for (File f : file)
            {
                if (f.isDirectory()) { 
                     file[] innerFiles = f.listFiles();
    
                     for(int i=0; i< innerFiles.length;i++){
                       Log.i("Name", innerFiles[i].getPath() + "");
                     }
            }
    
                if (f.isFile()) { ... do stuff }
            }