Java Relative Path Get relativePathFiles(String relativePath, final String... fileNamesRegex)

Here you can find the source of relativePathFiles(String relativePath, final String... fileNamesRegex)

Description

relative Path Files

License

Open Source License

Declaration

static Collection<String> relativePathFiles(String relativePath, final String... fileNamesRegex) 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Collection;

public class Main {
    static Collection<String> relativePathFiles(String relativePath, final String... fileNamesRegex) {
        relativePath = relativePath.trim();
        File dir = new File(relativePath).getAbsoluteFile();
        File[] jars = dir.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                if (pathname.isFile()) {
                    String fileName = pathname.getName();
                    for (String regex : fileNamesRegex) {
                        if (fileName.matches(regex)) {
                            return true;
                        }/*from w w w.j  av a 2  s.c  om*/
                    }
                }
                return false;
            }
        });
        ArrayList<String> paths = new ArrayList<String>(jars.length);
        relativePath = relativePath.length() == 0 ? "" : relativePath + "/";
        for (File jar : jars) {
            paths.add(relativePath + jar.getName());
        }
        return paths;
    }
}

Related

  1. relativePath(File src, File dest)
  2. relativePath(final File root, final File file)
  3. relativePath(final String inputPath, final File file)
  4. relativePath(String origin, String target)
  5. relativePath(String p_absolutePath, String p_currentPath)
  6. relativeTo(File peer, String filename)
  7. relativeToAbsoluteFilePath(String s)
  8. relativize(File base, File absolute)
  9. relativize(File base, File child)