Java Folder Read getFiles(File... repertoires)

Here you can find the source of getFiles(File... repertoires)

Description

Return all the files (not directories) in the directories "repertoires" recursively.

License

Open Source License

Parameter

Parameter Description
repertoires directories

Return

files in directories "repertoires"

Declaration


public static File[] getFiles(File... repertoires) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.util.ArrayList;

public class Main {
    /**//from   w  w  w .jav  a2  s  .  c  o  m
    *Return all the files (not directories) in the directories "repertoires" recursively.
    *@param repertoires directories
    *@return files in directories "repertoires"
    */

    public static File[] getFiles(File... repertoires) {
        File[] ret = null;
        ArrayList<File> files = new ArrayList<File>();
        for (int i = 0; i < repertoires.length; i++)
            addDirectoryContents(files, repertoires[i]);
        ret = new File[files.size()];
        for (int i = 0; i < files.size(); i++)
            ret[i] = files.get(i);
        return ret;

    }

    /**
    *Add to the ArrayList<File>" files" all files in the directory "dir" recursively.
    *@param files 
    *@param dir files in this directory will be added to "files"
    */

    private static void addDirectoryContents(ArrayList<File> files, File dir) {
        File[] files1 = dir.listFiles();
        if (files1 != null) {
            for (int i = 0; i < files1.length; i++) {
                if (files1[i].isDirectory())
                    addDirectoryContents(files, files1[i]);
                else
                    files.add(files1[i]);
            }
        }
    }
}

Related

  1. getFiles(File file, Collection ret)
  2. getFiles(File folder)
  3. getFiles(File folder)
  4. getFiles(File folder)
  5. getFiles(File indir)
  6. getFiles(final File dir)
  7. getFiles(final File root, final String[] endings)
  8. getFiles(final String classPath)
  9. getFiles(final String path, Vector files)