列表中的一个列表,所有的文件夹中的所有文件 [英] List all the files from all the folder in a single list

查看:199
本文介绍了列表中的一个列表,所有的文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在寻找解决方案,以从​​根/ Android设备列出的所有文件。

Hi I am looking for the solution to list all the files from root/Android device.

假设有3文件夹的根目录中,但我想显示在一个列表中的所有这些文件夹中的所有文件。

Suppose there are 3 folder inside root directory,but I want to display all the files in all of these folder in a single list..

现在如果我使用

       File f=new File("/sdcard");

然后,它会列出从SD卡的文件夹中的所有文件only..and如果我将使用

Then it will list all the files from the sdcard folder only..and If I will use

       File f=new File("/download");

然后,它会列出从下载文件夹中的所有文件只有..和我是否会用

Then it will list all the files from download folder only ..and if I will use

       File f=new File("/");

然后将只列出根direcoty文件...不是内部/ SD卡或/和下载文件。

Then it will list only root direcoty files...not the files inside /sdcard or /download..

因此​​,我将遵循什么样的步骤来列出所有的文件过滤器,以里面所有的根文件夹列表中唯一的.csv文件。

So what steps shall I follow to list all the files with a filter to list only .csv files from all the folder inside root.

谢谢..

推荐答案

试试这个:

 .....
 List<File> files = getListFiles(new File("YOUR ROOT")); 
 ....
 private List<File> getListFiles(File parentDir) {
    ArrayList<File> inFiles = new ArrayList<File>();
    File[] files = parentDir.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            inFiles.addAll(getListFiles(file));
        } else {
            if(file.getName().endsWith(".csv")){
                inFiles.add(file);
            }
        }
    }
    return inFiles;
}

这篇关于列表中的一个列表,所有的文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆