Java Utililty Methods Folder Read

List of utility methods to do Folder Read

Description

The list of methods to do Folder Read are organized into topic(s).

Method

ListgetFilesComposingPath(File aFile)
Get the list of all File objects that compose the path to the given File object
List<File> fileList;
if (aFile == null) {
    fileList = new ArrayList<File>();
} else {
    fileList = getFilesComposingPath(aFile.getParentFile());
    fileList.add(aFile);
return fileList;
...
intgetFilesCount(File archiveFile)
get Files Count
ZipInputStream zipInput;
zipInput = new ZipInputStream(new FileInputStream(archiveFile));
ZipEntry zipEntry = zipInput.getNextEntry();
int count = 0;
while (zipEntry != null) {
    if (!zipEntry.isDirectory()) {
        count++;
    zipEntry = zipInput.getNextEntry();
zipInput.closeEntry();
zipInput.close();
return count;
StringgetFileset(File projectFolder)
get Fileset
template = template.replace("<FOLDER>", projectFolder.getAbsolutePath());
return template;
File[]getFilesFolder(String path)
Gets the files folder.
File file = new File(path);
return file.listFiles();
ListgetFilesFor(List patientSets, File inputDirectory)
Get files for specific sets of patients.
List<File> files = new ArrayList<>();
for (Integer set : patientSets) {
    final int setNum = set;
    for (File file : inputDirectory.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.contains(String.format("ID%03d", setNum));
    })) {
        if (!file.isHidden()) {
            files.add(file);
return files;
CollectiongetFilesForDirectory(File dir)
Method to return the files below the specified directory.
if (dir == null) {
    return null;
Collection files = new HashSet();
File[] dirFiles = dir.listFiles();
if (dirFiles != null) {
    for (int i = 0; i < dirFiles.length; i++) {
        if (dirFiles[i].isFile()) {
...
ArrayListgetFilesForFolder(File folder)
get Files For Folder
ArrayList<File> files = new ArrayList<File>();
for (File file : folder.listFiles()) {
    if (file.isDirectory()) {
        ArrayList<File> childFolderFiles = new ArrayList<File>();
        childFolderFiles = getFilesForFolder(file);
        files.addAll(childFolderFiles);
    } else {
        files.add(file);
...
ArrayListgetFilesForPattern(String pathToScan, String startWith, String endsWith)
Returns fileArray ArrayList of File objects that match a pattern in the specified directory.
String target_file; 
File folderToScan = new File(pathToScan);
File[] listOfFiles = folderToScan.listFiles();
ArrayList<File> list = new ArrayList();
for (File file : listOfFiles) {
    if (file.isFile()) {
        target_file = file.getName();
        if (target_file.startsWith(startWith) && target_file.endsWith(endsWith)) {
...
ListgetFilesFromClassPath(String classpath)
get Files From Class Path
File dir = new File(classpath);
return getFilesFromDir(dir);
File[]getFilesFromDiskWorker(File folderToLoad, final String searchPattern, final boolean justFolders)
Get the list of sorted files in folder or null if parent folder doesn't exist or pattern is not valid.
try {
    if (folderToLoad != null && folderToLoad.exists()) {
        File folder = folderToLoad.isDirectory() ? folderToLoad : folderToLoad.getParentFile();
        FilenameFilter fileFilter = new FilenameFilter() {
            Pattern pat = searchPattern == null || searchPattern.isEmpty() ? null
                    : Pattern.compile(searchPattern);
            @Override
            public boolean accept(File file, String name) {
...