Here you can find the source of getFileListingNoSort(File aStartingDir, boolean recursive)
Parameter | Description |
---|---|
aStartingDir | a parameter |
recursive | a parameter |
private static List<File> getFileListingNoSort(File aStartingDir, boolean recursive)
//package com.java2s; /*/* w w w . ja va 2s . c om*/ Copyright (C) 2010-2011 Tim Telcik <telcik@gmail.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { /** * Get a list of all files/directories in a directory structure. * Can optionally recurse into any number of nested directories. * * @param aStartingDir * @param recursive * @return List<File> */ private static List<File> getFileListingNoSort(File aStartingDir, boolean recursive) { List<File> result = new ArrayList<File>(); File[] filesAndDirs = aStartingDir.listFiles(); List<File> filesDirs = Arrays.asList(filesAndDirs); for (File file : filesDirs) { result.add(file); // always add, even if directory if (file.isDirectory() && recursive) { List<File> nestedList = getFileListingNoSort(file, recursive); result.addAll(nestedList); } } return result; } }