Java File List Load getFileList(File f, FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden, ArrayList list)

Here you can find the source of getFileList(File f, FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden, ArrayList list)

Description

Get file list from specified directory applying the specified parameters

License

Open Source License

Declaration

private static void getFileList(File f, FileFilter filter, boolean recursive, boolean wantDirectory,
        boolean wantHidden, ArrayList<File> list) 

Method Source Code

//package com.java2s;
/*/*from   w  w w.  j  av  a  2 s  .  c o  m*/
 * Copyright 2010, 2011 Institut Pasteur.
 * 
 * This file is part of ICY.
 * 
 * ICY is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ICY is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ICY. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;
import java.io.FileFilter;

import java.util.ArrayList;

public class Main {
    /**
     * Get file list from specified directory applying the specified parameters
     */
    public static ArrayList<File> getFileList(String path, boolean recursive, boolean wantDirectory,
            boolean wantHidden) {
        return getFileList(new File(getGenericPath(path)), null, recursive, wantDirectory, wantHidden);
    }

    /**
     * Get file list from specified directory applying the specified parameters
     */
    public static ArrayList<File> getFileList(String path, FileFilter filter, boolean recursive,
            boolean wantDirectory, boolean wantHidden) {
        final ArrayList<File> result = new ArrayList<File>();

        getFileList(new File(getGenericPath(path)), filter, recursive, wantDirectory, wantHidden, result);

        return result;
    }

    /**
     * Get file list from specified directory applying the specified parameters
     */
    public static ArrayList<File> getFileList(File file, boolean recursive, boolean wantDirectory,
            boolean wantHidden) {
        return getFileList(file, null, recursive, wantDirectory, wantHidden);
    }

    /**
     * Get file list from specified directory applying the specified parameters
     */
    public static ArrayList<File> getFileList(File file, FileFilter filter, boolean recursive,
            boolean wantDirectory, boolean wantHidden) {
        final ArrayList<File> result = new ArrayList<File>();

        getFileList(file, filter, recursive, wantDirectory, wantHidden, result);

        return result;
    }

    /**
     * Get file list from specified directory applying the specified parameters
     */
    private static void getFileList(File f, FileFilter filter, boolean recursive, boolean wantDirectory,
            boolean wantHidden, ArrayList<File> list) {
        final File[] files = f.listFiles(filter);

        if (files != null) {
            for (File file : files) {
                if ((!file.isHidden()) || wantHidden) {
                    if (file.isDirectory()) {
                        if (wantDirectory)
                            list.add(file);
                        if (recursive)
                            getFileList(file, filter, true, wantDirectory, wantHidden, list);
                    } else
                        list.add(file);
                }
            }
        }
    }

    /**
     * Get file list from specified directory applying the specified parameters.<br>
     * This function does not return sub directory.
     */
    public static ArrayList<File> getFileList(String path, boolean recursive, boolean wantHidden) {
        return getFileList(path, recursive, false, wantHidden);
    }

    /**
     * Get file list from specified directory applying the specified parameters<br>
     * This function does not return sub directory.
     */
    public static ArrayList<File> getFileList(String path, FileFilter filter, boolean recursive,
            boolean wantHidden) {
        return getFileList(path, filter, recursive, false, wantHidden);
    }

    /**
     * Get file list from specified directory applying the specified parameters<br>
     * This function does not return sub directory.
     */
    public static ArrayList<File> getFileList(File file, boolean recursive, boolean wantHidden) {
        return getFileList(file, recursive, false, wantHidden);
    }

    /**
     * Get file list from specified directory applying the specified parameters<br>
     * This function does not return sub directory.
     */
    public static ArrayList<File> getFileList(File file, FileFilter filter, boolean recursive, boolean wantHidden) {
        return getFileList(file, filter, recursive, false, wantHidden);
    }

    public static String getGenericPath(String path) {
        if (path != null)
            return path.replace('\\', '/');

        return null;
    }
}

Related

  1. getFileList(File dir, ArrayList list)
  2. getFileList(File dir, Set arrayList)
  3. getFileList(File dir, String regex)
  4. getFileList(File dirFile, final String filenamePrefix)
  5. getFileList(File f)
  6. getFileList(File file)
  7. getFileList(File file)
  8. getFileList(File file, String[] suffixs)
  9. getFileList(File folder, String type)