Here you can find the source of getFilesForFolder(File folder, boolean recursive)
Parameter | Description |
---|---|
folder | a parameter |
recursive | a parameter |
public static List<File> getFilesForFolder(File folder, boolean recursive)
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { /**/*ww w.java2s . c o m*/ * Returns a sorted list of files contained in the directory. * * @param folder * @param recursive * @return */ public static List<File> getFilesForFolder(File folder, boolean recursive) { List<File> fileList = new ArrayList<File>(); listFilesForFolder(fileList, folder, recursive); // File implements Comparable and sorts by pathname by default Collections.sort(fileList); return fileList; } private static void listFilesForFolder(final List<File> fileList, final File folder, boolean recursive) { for (final File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory() && recursive) { listFilesForFolder(fileList, fileEntry, recursive); } else { fileList.add(fileEntry); } } } }