Here you can find the source of getFileList(final File dir, final String extension, final List
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 |
public static void getFileList(final File dir, final String extension, final List<File> list, final int maxDepth)
//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); } } } }