Java Directory to File List getAllFiles(File directory, boolean hidden)

Here you can find the source of getAllFiles(File directory, boolean hidden)

Description

get All Files

License

Open Source License

Declaration

public static File[] getAllFiles(File directory, boolean hidden) 

Method Source Code


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

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static File[] getAllFiles(File directory, boolean hidden) {

        File[] files = directory.listFiles();

        List<File> fileLst = new ArrayList<File>();

        for (File file : files) {
            File[] fs = getFile(file, hidden);
            for (File f : fs) {
                fileLst.add(f);/*from w ww . j ava  2s .c o m*/
            }
        }

        return fileLst.toArray(new File[fileLst.size()]);

    }

    public static File[] getFile(String path, boolean hidden) {
        return getFile(new File(path), hidden);
    }

    public static File[] getFile(File directory, boolean hidden) {

        if (!directory.exists()) {
            return null;
        } else if (!hidden && directory.isHidden()) {
            return new File[] {};
        } else if (directory.isFile()) {
            return new File[] { directory };
        } else if (directory.isDirectory()) {
            return getAllFiles(directory, hidden);
        }
        return null;

    }
}

Related

  1. getAllFiles(File dir, List fileList)
  2. getAllFiles(File dir, List fileList)
  3. getAllFiles(File dir, Pattern filter)
  4. getAllFiles(File directory)
  5. getAllFiles(File directory)
  6. getAllFiles(File directory, String rootPath)
  7. getAllFiles(File inFileOrDir, boolean recurseDir)
  8. getAllFiles(File input)
  9. getAllFiles(File outputDir, List files)