Here you can find the source of getResourceNamesFromDir(File dir, String extension)
Parameter | Description |
---|---|
dir | a parameter |
extension | a parameter |
public static List<String> getResourceNamesFromDir(File dir, String extension)
//package com.java2s; /*/* w w w .j av a2 s .com*/ * #%L * ELK Utilities for Testing * * $Id$ * $HeadURL$ * %% * Copyright (C) 2011 - 2012 Department of Computer Science, University of Oxford * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * @param dir * @param extension * @return A list of paths relative to {@code dir} of the files from * {@code dir} with the provided filename extension. The directory * is traversed recursively. */ public static List<String> getResourceNamesFromDir(File dir, String extension) { List<String> testResources = new ArrayList<String>(); collectResourceNamesFromDir(dir, "", extension, testResources); return testResources; } private static void collectResourceNamesFromDir(final File file, final String prefix, final String extension, final Collection<String> result) { final String fileName = file.getName(); if (file.isDirectory()) { final File[] innerFiles = file.listFiles(); if (innerFiles == null) { throw new RuntimeException("Error listing directory " + file); } // else for (final File innerFile : innerFiles) { collectResourceNamesFromDir(innerFile, prefix + fileName + File.separator, extension, result); } return; } // else file is not a directory if (fileName.endsWith("." + extension)) { result.add(prefix + fileName); } } }