简体   繁体   English

获取内部和外部存储中所有文件夹中的所有文件

[英]Get all files in all folders in internal and external storage

I'm working on a project on android studio and I need help.. How can I search for a file by its name in all folders in internal and external storage?? 我正在android studio上的一个项目上工作,需要帮​​助。如何在内部和外部存储中的所有文件夹中按文件名搜索文件?

I tried using for loop to search in internal.. And I tested if the file doesn't exist , the path will be the old path+the folder name. 我尝试使用for循环在内部进行搜索。并且测试了文件是否不存在,该路径将为旧路径+文件夹名称。 It didn't work out 它没有解决

    public void getAllDir(File dir) {
        String pdfPattern = ".pdf or .txt or .jpg etc..";

        File listFile[] = dir.listFiles();

        if (listFile != null) {
            for (int i = 0; i < listFile.length; i++) {

                if (listFile[i].isDirectory()) {
                    getAllDir(listFile[i]);
                } else {
                  if (listFile[i].getName().endsWith(pdfPattern)){
                                      //Do what ever u want

                  }
                }
            }
        }    
    }


and call this function like

getAllDir(Environment.getExternalStorageDirectory());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用MediaStore获取存储在android的内部存储和外部存储中的所有音乐文件? - How to get all music files stored in internal storage and external storage in android using MediaStore? 在Android中使用绝对路径获取内部和外部存储中所有文件(每个文件)的列表 - Get list of all files (every file) in both internal and external storage with absolute path in Android 如何从Android的内部和外部存储中获取所有.mp3文件 - How to get all .mp3 files from internal and external storage in android 如何从外部sdcard和手机存储中获取所有文件(移动存储内部)? - How to get all files from external sdcard and phone storage (internal with mobile memory)? Android - 如何从内部存储中获取所有文件路径或从内部存储中删除所有文件 - Android - How to get all file path from internal storage or delete all files from internal storage 如何使用Android中的MediaStore.Files从内部和外部存储中获取所有.pdf文件 - How can I get all .pdf files from Internal as well as External storage using MediaStore.Files in Android 内部存储文件夹和文件 - Internal storage folders and files Android-查找所有内部和外部存储 - Android - Find all internal and external storage 获取“外部存储”的所有路径的列表时,哪个路径指向内部存储? - Which path point to the internal storage when get a list of all paths of the “external storage”? 获取目录中的所有文件夹和文件 - Get all folders and files in a directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM