简体   繁体   中英

How to get all files from external sdcard and phone storage (internal with mobile memory)?

I try to get all files from mobile (both external sdcard and phone storage (internal with mobile memory)).

i try with this code Environment.getExternalStorageDirectory() . but from this i only able to get sd-card files not phone storage.

please help how can i get both memory location path or files.

File file[] = Environment.getExternalStorageDirectory().listFiles();
    recursiveFileFind(file);

public void recursiveFileFind(File[] file1){
int i = 0;
String filePath="";
     if(file1!=null){
    while(i!=file1.length){
        filePath = file1[i].getAbsolutePath();
            if(file1[i].isDirectory()){
                    File file[] = file1[i].listFiles();
            recursiveFileFind(file);
            }
        i++;
        //Log.d(i+"", filePath);
    }
  }
}

If this is not work then in below code u can give external path and

get all files.

private void getAllFilesOfDir(File directory) {
    Log.d(TAG, "Directory: " + directory.getAbsolutePath() + "\n");

    final File[] files = directory.listFiles();

    if ( files != null ) {
        for ( File file : files ) {
            if ( file != null ) {
                if ( file.isDirectory() ) {  // it is a folder...
                    getAllFilesOfDir(file);
                }
                else {  // it is a file...
                    Log.d(TAG, "File: " + file.getAbsolutePath() + "\n");
                }
            }
        }
    }
}

This code will give internal files.

    String[] SavedFiles;
    ArrayList<String> arrList;
    SavedFiles = getApplicationContext().fileList();


   arrList = new ArrayList<String>();
   if(SavedFiles != null)
          {
              for(int i=0; i<SavedFiles.length; i++)
              {
                  arrList.add(SavedFiles[i]);
              }


          }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM