Java Folder Read getFilesByRegxFileName(String dir, final String regxName)

Here you can find the source of getFilesByRegxFileName(String dir, final String regxName)

Description

get Files By Regx File Name

License

Apache License

Declaration

public static File[] getFilesByRegxFileName(String dir, final String regxName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileFilter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static File[] getFilesByRegxFileName(String dir, final String regxName) {
        if (dir == null)
            throw new NullPointerException("dir must not be null");
        File dirc = new File(dir);
        if (!dirc.exists() || !dirc.isDirectory()) {
            throw new IllegalArgumentException("dir must be exists directory");
        }//  w  ww  .java2  s  . com
        File[] files = dirc.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                Pattern pattern = Pattern.compile(regxName);
                Matcher matcher = pattern.matcher(pathname.getName());
                if (pathname.isDirectory() || (!(matcher.find()))) {
                    return false;
                }
                return true;
            }
        });
        return files;
    }
}

Related

  1. getFilesArray(File baseStorePath, final String fileNameSearchPattern)
  2. getFilesAsArrayList(String path)
  3. getFilesByDate(String directory, final boolean earliestFirst)
  4. getFilesByName(File path, String name)
  5. getFilesByPath(String toDir)
  6. getFilesByType(String fileType, String path)
  7. getFilesByType(String path, final String type)
  8. getFilesCannotAccess(File... files)
  9. getFilesComposingPath(File aFile)