Java Directory to File List getAllFilesInDirectory(String dirName)

Here you can find the source of getAllFilesInDirectory(String dirName)

Description

get All Files In Directory

License

Apache License

Declaration

public static List<File> getAllFilesInDirectory(String dirName) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<File> getAllFilesInDirectory(String dirName) {
        File folder = new File(dirName);
        File[] listOfFiles = folder.listFiles();
        List<File> result = new ArrayList<>();

        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
                result.add(listOfFiles[i]);
            }/*  ww w .  j  a  va 2 s  .co m*/
        }
        return result;
    }
}

Related

  1. getAllFilesInAllSubDirectories(File parentDir, FileFilter filter)
  2. getAllFilesInDir(boolean traverseSubDirs, File dir, boolean includeHidden, String prefix)
  3. getAllFilesInDirectory(File dir)
  4. getAllFilesInDirectory(File directory, List files)
  5. getAllFilesInDirectory(String directoryPath)
  6. getAllFilesInDirectory(String path)
  7. getAllFilesInDirMatchingPattern(String directory, final String regex, final boolean first_match2)
  8. getAllFilesInFolder(File rootFolder, FileFilter filter, int maxFilesRequired)
  9. getAllFilesInFolder(String folder)