Java Folder Read getFilesForPattern(String pathToScan, String startWith, String endsWith)

Here you can find the source of getFilesForPattern(String pathToScan, String startWith, String endsWith)

Description

Returns fileArray ArrayList of File objects that match a pattern in the specified directory.

License

Open Source License

Parameter

Parameter Description
pathToScan The path to look for the matching files
startWith The beginning portion of the file name
endsWith The ending portion of the file name (i.e. ".jar")

Return

fileArray An ArrayList of

Declaration

public final static ArrayList<File> getFilesForPattern(String pathToScan, String startWith, String endsWith) 

Method Source Code

//package com.java2s;
/*/*from   w w w . j  a  v a 2 s. c  o  m*/
 * JBoss, Home of Professional Open Source.
 *
 * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing.
 *
 * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors.
 */

import java.io.File;

import java.util.ArrayList;

public class Main {
    /**
     * Returns fileArray {@code ArrayList} of {@code File} objects that match a pattern in the specified directory. 
     * @param pathToScan The path to look for the matching files
     * @param startWith The beginning portion of the file name
     * @param endsWith The ending portion of the file name (i.e. ".jar")
     * @return fileArray An ArrayList of 
     * @since 8.5
     */
    public final static ArrayList<File> getFilesForPattern(String pathToScan, String startWith, String endsWith) {
        String target_file; // fileThatYouWantToFilter
        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)) {
                    list.add(file);
                }
            }
        }

        return list;
    }
}

Related

  1. getFileset(File projectFolder)
  2. getFilesFolder(String path)
  3. getFilesFor(List patientSets, File inputDirectory)
  4. getFilesForDirectory(File dir)
  5. getFilesForFolder(File folder)
  6. getFilesFromClassPath(String classpath)
  7. getFilesFromDiskWorker(File folderToLoad, final String searchPattern, final boolean justFolders)
  8. getFileSimpleName(final File f)
  9. getFilesInClassPath(String path, String endsWith)