Java Directory to File List getAllFilesFromFolder(File aFolder, FilenameFilter filenameFilter)

Here you can find the source of getAllFilesFromFolder(File aFolder, FilenameFilter filenameFilter)

Description

DOC xqliu Comment method "getAllFilesFromFolder".

License

Open Source License

Parameter

Parameter Description
aFolder a parameter
filenameFilter a parameter

Declaration

public static List<File> getAllFilesFromFolder(File aFolder, FilenameFilter filenameFilter) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

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

import java.io.FilenameFilter;

import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

public class Main {
    /**//from   w  w w.  jav  a 2 s . c  om
     * DOC sgandon Comment method "getAllFilesFromFolder".
     * 
     * @param aFolder
     * @param fileList
     * @param filenameFilter
     */
    public static void getAllFilesFromFolder(File aFolder, List<File> fileList, FilenameFilter filenameFilter) {
        File[] folderFiles = aFolder.listFiles(filenameFilter);
        if (fileList != null && folderFiles != null) {
            Collections.addAll(fileList, folderFiles);
        }
        File[] allFolders = aFolder.listFiles(new FileFilter() {

            @Override
            public boolean accept(File arg0) {
                return arg0.isDirectory();
            }
        });
        if (allFolders != null) {
            for (File folder : allFolders) {
                getAllFilesFromFolder(folder, fileList, filenameFilter);
            }
        }
    }

    /**
     * DOC xqliu Comment method "getAllFilesFromFolder".
     * 
     * @param aFolder
     * @param filenameFilter
     * @return
     */
    public static List<File> getAllFilesFromFolder(File aFolder, FilenameFilter filenameFilter) {
        List<File> files = new ArrayList<File>();
        getAllFilesFromFolder(aFolder, files, filenameFilter);
        return files;
    }
}

Related

  1. getAllFilesByProfix(String path, String suffix, List files)
  2. getAllFilesEndingWith(String path, final String extension)
  3. getAllFilesEndingWith(String path, final String extension)
  4. getAllFilesForType(File dir, FilenameFilter filter)
  5. getAllFilesFromDir(File dir)
  6. getAllFilesFromFolder(File sampleFolder, ArrayList fileList, FilenameFilter filenameFilter)
  7. getAllFilesIn(File dir, final String type)
  8. getAllFilesInAllSubDirectories(File parentDir, FileFilter filter)
  9. getAllFilesInDir(boolean traverseSubDirs, File dir, boolean includeHidden, String prefix)