Here you can find the source of getAllFilesMatchingThisPatternIgnoreCase(String sDirectoryPath, String sPattern)
Parameter | Description |
---|---|
sDirectoryPath | The directory path |
sPattern | The pattern to match against <p> |
private static String[] getAllFilesMatchingThisPatternIgnoreCase(String sDirectoryPath, String sPattern)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.Vector; public class Main { /**//from w ww .j a va2 s. c o m * Returns the set of all files in the given directory, matching the given * pattern (ignoring case) * <p> * * @param sDirectoryPath * The directory path * @param sPattern * The pattern to match against * <p> * @return The required list of files */ private static String[] getAllFilesMatchingThisPatternIgnoreCase(String sDirectoryPath, String sPattern) { String[] asAllFiles = getAllFiles(sDirectoryPath); Vector vsFiltered = new Vector(); for (int i = 0; i < asAllFiles.length; i++) { if (asAllFiles[i].toLowerCase().matches(sPattern.toLowerCase())) { vsFiltered.add(asAllFiles[i]); } } String[] asFilteredFiles = new String[vsFiltered.size()]; for (int i = 0; i < vsFiltered.size(); i++) { asFilteredFiles[i] = vsFiltered.elementAt(i).toString(); } return asFilteredFiles; } /** * Returns the set of all files in the given directory * <p> * * @param sDirectoryPath * The directory path * <p> * @return The required list of files */ private static String[] getAllFiles(String sDirectoryPath) { if (sDirectoryPath == null) { return new String[0]; } File fileThisDirectory = new File(sDirectoryPath); if (fileThisDirectory.isDirectory() == false) { return new String[0]; } else { String[] asFileList = fileThisDirectory.list(); if (asFileList == null || asFileList.length == 0) { return asFileList; } return asFileList; } } }