Java File List Load getFileList(final List fileList, final File root, final File[] ignoreList)

Here you can find the source of getFileList(final List fileList, final File root, final File[] ignoreList)

Description

get File List

License

Open Source License

Declaration

public static void getFileList(final List<File> fileList, final File root, final File[] ignoreList) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.List;

public class Main {
    public static void getFileList(final List<File> fileList, final File root, final File[] ignoreList) {
        final File[] list = root.listFiles();

        if (list == null) {
            return;
        }/* w w  w.  ja  v  a  2s . c  o m*/

        for (final File f : list) {
            if (f.isDirectory() && !isIgnored(ignoreList, f)) {
                getFileList(fileList, f, ignoreList);
            } else {
                String filename = getFileExt(f.getName());

                if (filename.equalsIgnoreCase("jpg") || filename.equalsIgnoreCase("png")
                        || filename.equalsIgnoreCase("mp4")) {
                    fileList.add(f);
                }
            }
        }
    }

    public static void getFileList(final List<File> fileList, final File root, FileFilter filter) {
        final File[] list = root.listFiles(filter);

        if (list == null) {
            return;
        }

        for (final File f : list) {
            if (f.isDirectory()) {
                fileList.add(f);
                getFileList(fileList, f, filter);
            } else {
                fileList.add(f);
            }
        }
    }

    private static boolean isIgnored(File[] ignoreList, File file) {
        boolean result = false;

        for (File item : ignoreList) {
            if (item.getName().equalsIgnoreCase(file.getName())) {
                result = true;

                // Log.d(TAG, "Skipping folder: " + file);
            }
        }

        return result;
    }

    public static String getFileExt(String fileName) {
        int index = fileName.lastIndexOf(".") + 1;
        String ext = fileName.substring(index, fileName.length());
        return ext;
    }
}

Related

  1. getFileList(File file, String[] suffixs)
  2. getFileList(File folder, String type)
  3. getFileList(File sourceDirectory, final String extension)
  4. getFileList(File[] fileArray)
  5. getFileList(final File dir, final String extension, final List list, final int maxDepth)
  6. getFileList(final String location)
  7. getFileList(Map>> map, File dir, T key)
  8. getFileList(String dir)
  9. getFileList(String dir)