如何读取母文件夹内的子文件夹和其他类型的子文件

有一个母文件夹ABC,母文件下有n个jpg图片和数个pdf文件和数个文件夹,现在想要
将所有的内容都展示出来,要如何实现
类似于如何的图片模式,里面图集的部分是图片,但无法展开
图片说明

/**

  • 获取指定目录内所有文件路径
  • @param dirPath 需要查询的文件目录
  • @param _type 查询类型,比如mp3什么的
    */
    public static JSONArray getAllFiles(String dirPath, String _type) {
    File f = new File(dirPath);
    if (!f.exists()) {//判断路径是否存在
    return null;
    }

    File[] files = f.listFiles();

    if(files==null){//判断权限
    return null;
    }

    JSONArray fileList = new JSONArray();
    for (File _file : files) {//遍历目录
    if(_file.isFile() && _file.getName().endsWith(_type)){
    String _name=_file.getName();
    String filePath = _file.getAbsolutePath();//获取文件路径
    String fileName = _file.getName().substring(0,_name.length()-4);//获取文件名
    // Log.d("LOGCAT","fileName:"+fileName);
    // Log.d("LOGCAT","filePath:"+filePath);
    try {
    JSONObject _fInfo = new JSONObject();
    _fInfo.put("name", fileName);
    _fInfo.put("path", filePath);
    fileList.put(_fInfo);
    }catch (Exception e){
    }
    } else if(_file.isDirectory()){//查询子目录
    getAllFiles(_file.getAbsolutePath(), _type);
    } else{
    }
    }
    return fileList;
    }