簡體   English   中英

獲取內部和外部存儲中所有文件夾中的所有文件

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

我正在android studio上的一個項目上工作,需要幫​​助。如何在內部和外部存儲中的所有文件夾中按文件名搜索文件?

我嘗試使用for循環在內部進行搜索。並且測試了文件是否不存在,該路徑將為舊路徑+文件夾名稱。 它沒有解決

    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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM