Java Folder Read by Filter getFiles(String sourceName, FilenameFilter filter)

Here you can find the source of getFiles(String sourceName, FilenameFilter filter)

Description

Get the list of files contained in parent parameter directory

License

Open Source License

Parameter

Parameter Description
sourceName a parameter
filter a parameter

Declaration

public static ArrayList getFiles(String sourceName, FilenameFilter filter) 

Method Source Code

//package com.java2s;
/*/*  ww  w  . j a  v  a 2 s.  c  o  m*/
 * Copyright (c) Fiorano Software Pte. Ltd. and affiliates. All rights reserved. http://www.fiorano.com
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.txt file.
 */

import java.io.*;

import java.util.*;

public class Main {
    /**
     * Get the list of files contained in parent parameter directory
     *
     * @param sourceName
     * @param filter
     * @return
     */
    public static ArrayList getFiles(String sourceName, FilenameFilter filter) {
        File sourceFile = new File(sourceName);
        ArrayList result = new ArrayList();

        if (!sourceFile.exists() || !sourceFile.isDirectory())
            return result;

        String[] fileNames = sourceFile.list(filter);

        if (fileNames == null)
            return result;

        for (int i = 0; i < fileNames.length; i++) {
            File file = new File(fileNames[i]);

            if (file.isDirectory())
                result.addAll(getFiles(fileNames[i], filter));
            else
                result.add(fileNames[i]);
        }

        return result;
    }
}

Related

  1. getFiles(File folder, FilenameFilter filter)
  2. getFiles(File root, boolean recurse, FileFilter fileFilter)
  3. getFiles(final File directory, final FilenameFilter filter)
  4. getFiles(String name, FileFilter filter, boolean includeSubtree)
  5. getFiles(String sourceDirPath, FilenameFilter filter, Comparator comparator)
  6. getFilesOnlyFilter()
  7. getFilesRealWorking(File aStartingDir, FilenameFilter filter)
  8. getFilesUnder(String path, FileFilter fileFilter)
  9. getFilesWithFilter(String DirectoryName, FilenameFilter Filter)