Java UTF8 getFiles(String InputFilePath)

Here you can find the source of getFiles(String InputFilePath)

Description

get Files

License

Apache License

Declaration

public static ArrayList<File> getFiles(String InputFilePath) throws Exception 

Method Source Code

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

import java.io.File;

import java.nio.file.FileSystems;

import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;

public class Main {
    public static ArrayList<File> getFiles(String InputFilePath) throws Exception {
        ArrayList<File> fileList = new ArrayList<File>();
        File dir = null;//from  w w  w . j  a  v  a  2  s  .  co m
        String filePattern = null;
        InputFilePath.trim();
        // Handle unix\URI style path
        if (InputFilePath.lastIndexOf('/') > 0) {
            dir = new File((InputFilePath.substring(0, InputFilePath.lastIndexOf('/') + 1) == "" ? "."
                    : InputFilePath.substring(0, InputFilePath.lastIndexOf('/') + 1) + "\\"));
            filePattern = (InputFilePath.substring(InputFilePath.lastIndexOf('/') + 1));
        }
        // handle windows style path
        else if (InputFilePath.lastIndexOf('\\') > 0) {
            dir = new File(InputFilePath.substring(0, InputFilePath.lastIndexOf('\\') + 1));
            filePattern = (InputFilePath.substring(InputFilePath.lastIndexOf('\\') + 1));
        }
        // User has asked us to use current working directory
        else {
            dir = new File(".");
            filePattern = InputFilePath;
        }
        PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + filePattern);

        if (!dir.isDirectory())
            throw new Exception("Not a directory : \"" + dir.getAbsolutePath() + "\". Build from the pattern : "
                    + InputFilePath);

        File[] InputfileObj = dir.listFiles();

        if (!dir.exists() || InputfileObj == null)
            return null;
        for (int i = 0; i < InputfileObj.length; i++)
            if (matcher.matches(Paths.get(InputfileObj[i].getName()))) {
                fileList.add(InputfileObj[i]);
            }

        return fileList;
    }
}

Related

  1. fromUTF8(byte[] bytes)
  2. fromUTF8(byte[] bytes)
  3. generateRawUTF8Bytes(final String string)
  4. getBytesUtf8(final String string)
  5. getFile(String outputFolder, String fileName)
  6. getOutputFromCommand(boolean print, List command)
  7. getStringFromUTF8Bytes(byte[] utf8Bytes)
  8. getUtf8()
  9. getUTF8()