Java File List Load getFileList(final File dir, final String extension, final List list, final int maxDepth)

Here you can find the source of getFileList(final File dir, final String extension, final List list, final int maxDepth)

Description

Searches a directory to the specified depth for library files.

This method is recursive so be careful with the maximum depth

License

Open Source License

Parameter

Parameter Description
dir the directory to being the search
extension the extension to search for
list the list of libraries found
maxDepth the current maximum depth

Declaration

public static void getFileList(final File dir, final String extension,
        final List<File> list, final int maxDepth) 

Method Source Code

//package com.java2s;
/**/*from ww  w  .ja  va 2  s.c  o m*/
 * Copyright (c) 2009 Stephen Evanchik
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Stephen Evanchik - initial implementation
 */

import java.io.File;

import java.util.List;

public class Main {
    /**
     * Searches a directory to the specified depth for library files.<br>
     * <br>
     * This method is recursive so be careful with the maximum depth
     *
     * @param dir
     *            the directory to being the search
     * @param extension
     *            the extension to search for
     * @param list
     *            the list of libraries found
     * @param maxDepth
     *            the current maximum depth
     */
    public static void getFileList(final File dir, final String extension,
            final List<File> list, final int maxDepth) {
        if (dir == null) {
            throw new IllegalArgumentException("Directory must not be null");
        }

        final File[] files = dir.listFiles();
        if (files == null) {
            return;
        }

        for (final File file : files) {
            if (file.isDirectory() && maxDepth > 0) {
                getFileList(file, extension, list, maxDepth - 1);
            } else if (file.getAbsolutePath().endsWith(extension)
                    || file.getAbsolutePath().endsWith(".zip")) {
                list.add(file);
            }
        }
    }
}

Related

  1. getFileList(File file)
  2. getFileList(File file, String[] suffixs)
  3. getFileList(File folder, String type)
  4. getFileList(File sourceDirectory, final String extension)
  5. getFileList(File[] fileArray)
  6. getFileList(final List fileList, final File root, final File[] ignoreList)
  7. getFileList(final String location)
  8. getFileList(Map>> map, File dir, T key)
  9. getFileList(String dir)