Java File List Load getFileListByRegex(String dir, final String regex)

Here you can find the source of getFileListByRegex(String dir, final String regex)

Description

Get the File list under the given directory by the regex.

License

Open Source License

Parameter

Parameter Description
dir the given directory
regex the given regulate expression.

Declaration

public static String[] getFileListByRegex(String dir, final String regex) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FilenameFilter;

public class Main {
    /**/*from  w  ww. ja  v a2  s.  c o  m*/
     * Get the File list under the given directory by the regex. If the
     * parameter dir is not a directory, return null.
     * 
     * @param dir
     *            the given directory
     * @param regex
     *            the given regulate expression.
     * @return
     */
    public static String[] getFileListByRegex(String dir, final String regex) {
        File file = new File(dir);

        if (!file.isDirectory()) {
            return null;
        }

        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.matches(regex);
            }
        };

        return file.list(filter);
    }

    public static boolean isDirectory(String path) {
        File file = new File(path);

        return file.isDirectory();
    }
}

Related

  1. getFileList(String path, String searchString)
  2. getFileList(String s)
  3. getFileList(String zipFilePath)
  4. getFileListByDFS(File file)
  5. getFileListByExtension(final String location, final String extension)
  6. getFileListDeep(File path)
  7. getFileListInFolder(String path)
  8. getFileListInFolderForImages(String imageFolder)
  9. getFileListing(File aStartingDir)