Here you can find the source of getFileList(File[] fileArray)
Parameter | Description |
---|---|
fileArray | array of files |
public static List<File> getFileList(File[] fileArray)
//package com.java2s; /* $Id$/* w w w .j av a2 s . co m*/ ***************************************************************************** * Copyright (c) 2009 Contributors - see below * 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: * thn ***************************************************************************** * * Some portions of this file was previously release using the BSD License: */ import java.io.File; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; public class Main { /** * Get a list of files from a file array, where the directory entries * are recursively resolved by all profile files inside the directory. * * @param fileArray array of files * @return list of files */ public static List<File> getFileList(File[] fileArray) { List<File> files = new ArrayList<File>(); for (int i = 0; i < fileArray.length; i++) { File file = fileArray[i]; files.addAll(getList(file)); } return files; } private static List<File> getList(File file) { List<File> results = new ArrayList<File>(); List<File> toDoDirectories = new LinkedList<File>(); Set<File> seenDirectories = new HashSet<File>(); toDoDirectories.add(file); while (!toDoDirectories.isEmpty()) { File curDir = toDoDirectories.remove(0); if (!curDir.isDirectory()) { // For some reason, this alleged directory is a single file // This could be that there is some confusion or just // the normal, that a single file was selected and is // supposed to be imported. results.add(curDir); continue; } // Get the contents of the directory File[] files = curDir.listFiles(); if (files != null) { for (File curFile : curDir.listFiles()) { // The following test can cause trouble with // links, because links are accepted as // directories, even if they link files. Links // could also result in infinite loops. For this // reason we don't do this traversing recursively. if (curFile.isDirectory()) { // If this file is a directory if (!seenDirectories.contains(curFile)) { toDoDirectories.add(curFile); seenDirectories.add(curFile); } } else { String s = curFile.getName().toLowerCase(); if (s.endsWith(".xmi") || s.endsWith(".uml") // for AndroMDA profiles || s.endsWith(".xmi.zip") || s.endsWith(".xml.zip")) { results.add(curFile); } } } } } return results; } }