Java Utililty Methods Directory to File List

List of utility methods to do Directory to File List

Description

The list of methods to do Directory to File List are organized into topic(s).

Method

ArrayListgetAllFile(File directory, boolean descendIntoSubDirectories, String endofFile, String hiddenFileSuffix)
get All File
ArrayList<File> resultList = new ArrayList<File>();
File[] f = directory.listFiles();
for (File file : f) {
    if (file != null && file.getName().toLowerCase().endsWith(endofFile)
            && !file.getName().startsWith("tn_") && !file.getName().startsWith(hiddenFileSuffix)) {
        resultList.add(file);
    if (descendIntoSubDirectories && file.isDirectory()) {
...
ListgetAllFile(List list, File rootFile)
recursively get the file list.
if (rootFile.getAbsolutePath().indexOf(".svn") < 0) {
    list.add(rootFile);
    if (rootFile.isDirectory()) {
        File[] files = rootFile.listFiles();
        Arrays.sort(files);
        for (File file : files) {
            getAllFile(list, file);
return list;
String[]getAllFile2(String Url)
get All File
File path = new File(Url);
String[] list;
list = path.list();
return list;
voidgetAllFileFromPath(File file, List fileList, String ed)
get All File From Path
if (file != null) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (File tmp : files) {
                getAllFileFromPath(tmp, fileList, ed);
    } else if (file.getName().toLowerCase().endsWith(ed)) {
        fileList.add(file);
ListgetAllFileName(String path)
get All File Name
File file = new File(path);
File[] fileName = file.listFiles();
List<String> list = new ArrayList<>();
if (file.isDirectory()) {
    for (File string : fileName)
        if (new File(string.getPath()).isFile()) {
            System.out.println(string.getPath());
            list.add(string.getPath());
...
ListGetAllFileName(String path)
Get All File Name
List<String> arrList = new ArrayList<String>();
File file = new File(path);
if (!file.exists()) {
    return arrList;
if (!file.isDirectory()) {
    return arrList;
String[] tempList = file.list();
File temp;
for (String aTempList : tempList) {
    if (path.endsWith(File.separator)) {
        temp = new File(path + aTempList);
    } else {
        temp = new File(path + File.separator + aTempList);
    if (temp.isFile()) {
        arrList.add(temp.getName());
return arrList;
voidgetAllFileName(String path, ArrayList fileName)
get filenames with sub-directory
File file = new File(path);
File[] files = file.listFiles();
String[] names = file.list();
if (names != null) {
    fileName.addAll(Arrays.asList(names));
for (File a : files) {
    if (a.isDirectory()) {
...
ArrayListgetAllFileNames(File basedir, String path)
The method return a list of all file names under the given directory and subdirectories of itself.
ArrayList<String> out = new ArrayList<String>();
File[] stage = basedir.listFiles();
for (File element : stage) {
    if (element.isFile()) {
        out.add(path + element.getName());
    if (element.isDirectory()) {
        out.addAll(getAllFileNames(element, path + element.getName() + SLASH));
...
ListgetAllFileNames(String path, String suffix, boolean isDepth)
get all names of file with specified suffix in a folder
List<String> fileNamesList = new ArrayList<String>();
File file = new File(path);
return listFileName(fileNamesList, file, suffix, isDepth);
String[]getAllFileNamesByPath(String path)
get all file names in a folder
File file = new File(path);
if (!file.exists()) {
    return null;
if (!file.isDirectory()) {
    return null;
String[] tempList = file.list();
...