Android Directory Content Get listFilesByDirectory(String directoryPath, boolean isOnlyFile)

Here you can find the source of listFilesByDirectory(String directoryPath, boolean isOnlyFile)

Description

list Files By Directory

Declaration

public static File[] listFilesByDirectory(String directoryPath,
            boolean isOnlyFile) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static File[] listFilesByDirectory(String directoryPath,
            boolean isOnlyFile) {
        File dir = new File(directoryPath);
        if (!dir.exists()) {
            return null;
        }/*  w  ww . j a  v a2s.co  m*/
        File[] files = null;
        if (isOnlyFile) {
            files = dir.listFiles(new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    if (pathname.isFile()) {
                        return true;
                    }
                    return false;
                }
            });
        } else {
            files = dir.listFiles();
        }
        return files;
    }
}

Related

  1. listDirs(String fileName)
  2. listFile(File dir)
  3. listFiles(File dir)
  4. listFiles(File rootDir, final String... sufix)
  5. getFileList(String path)
  6. listFiles(final String directory, final boolean root)