Here you can find the source of getFilesInFolder(File dir)
Parameter | Description |
---|---|
directory | The directory to check. |
public static File[] getFilesInFolder(File dir)
//package com.java2s; //License from project: LGPL import java.io.File; import java.util.ArrayList; public class Main { /**/*from w w w . j a va 2 s.c o m*/ * Returns all the Files in the specified directory and all sub-directories. * * <p> * For instance, If you have a folder, /Files/Documents/Maps, and call this method for Hello. It will return all the files in Documents and all the files in Maps! * * @param directory * The directory to check. * @return All the files in the folder and sub folders */ public static File[] getFilesInFolder(File dir) { return files(dir).toArray(new File[0]); } private static ArrayList<File> files(File dir) { ArrayList<File> files = new ArrayList<File>(); if (!dir.isDirectory()) throw new IllegalArgumentException("dir Isn't a Directory! " + dir); for (int i = 0; i < dir.listFiles().length; i++) { if (dir.listFiles()[i].isDirectory()) { files.addAll(files(dir.listFiles()[i])); } files.add(dir.listFiles()[i]); } return files; } }