Here you can find the source of getFileListingLogs(File aStartingDir)
Parameter | Description |
---|---|
aStartingDir | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
static private List<File> getFileListingLogs(File aStartingDir) throws Exception
//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; } }