Java File List Load getFileList(File file, String[] suffixs)

Here you can find the source of getFileList(File file, String[] suffixs)

Description

get File List

License

Apache License

Declaration

public static List<File> getFileList(File file, String[] suffixs) 

Method Source Code

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

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<File> getFileList(File file, String[] suffixs) {
        return getFileList(file, new ArrayList<File>(), suffixs, null, null);
    }//from ww  w . j ava 2s .  c o m

    public static List<File> getFileList(File file, String[] suffixs, String[] nameMatche, String[] nameNotMatche) {
        return getFileList(file, new ArrayList<File>(), suffixs, nameMatche, nameNotMatche);
    }

    public static List<File> getFileList(File file, List<File> fileList, String[] suffixs) {
        return getFileList(file, fileList, suffixs, null, null);
    }

    public static List<File> getFileList(File file, List<File> fileList, String[] suffixs, String[] nameMatche,
            String[] nameNotMatche) {
        if (file.getAbsolutePath().contains(".svn"))
            return fileList;
        if (file.isFile()) {
            String filename = file.getName();
            boolean isNameRight = false;
            if (nameMatche != null && nameMatche.length > 0) {
                for (String str : nameMatche) {
                    if (filename.toLowerCase().contains(str.toLowerCase())) {
                        isNameRight = true;
                        break;
                    }
                }
            } else {
                isNameRight = true;
            }
            if (isNameRight) {
                if (nameNotMatche != null && nameNotMatche.length > 0) {
                    for (String str : nameNotMatche) {
                        if (filename.toLowerCase().contains(str.toLowerCase())) {
                            isNameRight = false;
                            break;
                        }
                    }
                }
            }
            if (isNameRight) {
                if (suffixs == null || suffixs.length == 0) {
                    fileList.add(file);
                } else {
                    int index = filename.lastIndexOf(".");
                    if (index != -1) {
                        boolean isright = false;
                        String suffix = filename.substring(index, filename.length());
                        for (String str : suffixs) {
                            if (suffix.equalsIgnoreCase(str)) {
                                isright = true;
                                break;
                            }
                        }
                        if (isright) {
                            fileList.add(file);
                        }
                    }
                }
            }
        } else if (file.isDirectory()) {
            File[] fs = file.listFiles();
            for (File f : fs) {
                getFileList(f, fileList, suffixs, nameMatche, nameNotMatche);
            }
        }
        return fileList;
    }
}

Related

  1. getFileList(File dirFile, final String filenamePrefix)
  2. getFileList(File f)
  3. getFileList(File f, FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden, ArrayList list)
  4. getFileList(File file)
  5. getFileList(File file)
  6. getFileList(File folder, String type)
  7. getFileList(File sourceDirectory, final String extension)
  8. getFileList(File[] fileArray)
  9. getFileList(final File dir, final String extension, final List list, final int maxDepth)