Android Directory Content Get listFiles(final String directory, final boolean root)

Here you can find the source of listFiles(final String directory, final boolean root)

Description

list Files

Parameter

Parameter Description
directory the directory to iterate

Declaration

private static List<String> listFiles(final String directory,
        final boolean root) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//  ww w  .j  a  v  a  2  s .  c  om
     * 
     * @param directory the directory to iterate
     * @param if the file is a directory (first time it's called must be true)
     * @return
     */
    private static List<String> listFiles(final String directory,
            final boolean root) {
        final File file = new File(directory);

        final List<String> files = new ArrayList<String>();
        if (root) {
            files.add(directory);
        }

        final File[] tabFiles = file.listFiles();
        for (File f : tabFiles) {
            files.add(f.toString());
            if (f.isDirectory()) {
                files.addAll(listFiles(f.toString(), false));
            }

        }
        return files;

    }
}

Related

  1. listFile(File dir)
  2. listFiles(File dir)
  3. listFiles(File rootDir, final String... sufix)
  4. getFileList(String path)
  5. listFilesByDirectory(String directoryPath, boolean isOnlyFile)