SoFunction
Updated on 2025-04-06

Android traverses SDCARD folders and displays directory information

Android traverses SDCARD folders and displays directory information

private String mResult = new String(); private String[] mFileList = null;

1) Display all files/

File flist = new File("/mnt/sdcard");
  mFileList = ();
  for(String str: mFileList){
    mResult += str;
    mResult += "\n";
  }
TextView tv = (TextView)findViewById();
(());

2) Display the file with the specified suffix name/

FilenameFilter fnf = new FilenameFilter(){
    public boolean accept(File dir, String filename) {
      if((".mp3")) return true;
      return false;
    }
  };

  mFileList = (fnf);

  for(String str: mFileList){
    mResult += str;
    mResult += "\n";
  }

3) Show only the directory/

FileFilter ff = new FileFilter(){
    public boolean accept(File pathname) {
      return ();
    }
  };
File[] fileDir = (ff);
for (int i = 0; i < ; i++) {
    String str = fileDir[i].getName();
    mResult += str;
    mResult += "\n";
  }

Thank you for reading, I hope it can help you. Thank you for your support for this site!