Here you can find the source of getFilesForPattern(String pathToScan, String startWith, String endsWith)
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") |
public final static ArrayList<File> getFilesForPattern(String pathToScan, String startWith, String endsWith)
//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; } }