Java File List Load getFileListingLogs(File aStartingDir)

Here you can find the source of getFileListingLogs(File aStartingDir)

Description

Get all log files and directories and make recursive call.

License

Open Source License

Parameter

Parameter Description
aStartingDir a parameter

Exception

Parameter Description
Exception an exception

Declaration

static private List<File> getFileListingLogs(File aStartingDir) throws Exception 

Method Source Code

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

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {
    /**/*from   w  w w. ja  v a 2  s .com*/
     * Get all log files and directories and make recursive call.
     * 
     * @param aStartingDir
     * @return
     * @throws Exception
     */
    static private List<File> getFileListingLogs(File aStartingDir) throws Exception {
        List<File> result = new ArrayList<File>();
        File[] logfiles = aStartingDir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname.isFile();
            }
        });
        List<File> logFilesList = Arrays.asList(logfiles);
        File[] allDirs = aStartingDir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        for (File file : logFilesList) {
            if (file.getName().equals("log.xml")) {
                result.add(file);
            }
        }
        List<File> allDirsList = Arrays.asList(allDirs);
        Collections.sort(allDirsList, new Comparator<File>() {
            public int compare(File o1, File o2) {

                if (o1.lastModified() > o2.lastModified()) {
                    return +1;
                } else if (o1.lastModified() < o2.lastModified()) {
                    return -1;
                } else {
                    return 0;
                }
            }

        });
        for (File file : allDirsList) {
            if (!file.isFile()) {
                List<File> deeperList = getFileListingLogs(file);
                result.addAll(deeperList);
            }
        }
        return result;
    }
}

Related

  1. getFileListing(File aStartingDir)
  2. getFileListing(File dir)
  3. getFileListing(File directory)
  4. getFileListing(File file)
  5. getFileListing(File file, String... extension)
  6. getFileListingNoSort(File aStartingDir, boolean recursive)
  7. getFilesByExt(String dirName, String ext)
  8. getFilesFromDir(File dir)
  9. getFilesFromDirectory(final File folder)