Java Folder Read by Filter getFilesRealWorking(File aStartingDir, FilenameFilter filter)

Here you can find the source of getFilesRealWorking(File aStartingDir, FilenameFilter filter)

Description

get Files Real Working

License

Open Source License

Declaration

static public List<File> getFilesRealWorking(File aStartingDir,
            FilenameFilter filter) 

Method Source Code

//package com.java2s;
/*/*from w w w  .jav a 2 s . c  o m*/
 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description:
 *
 */

import java.io.File;

import java.io.FilenameFilter;

import java.util.ArrayList;
import java.util.Arrays;

import java.util.Iterator;
import java.util.List;

public class Main {
    static public List<File> getFilesRealWorking(File aStartingDir,
            FilenameFilter filter) {
        List<File> result = new ArrayList<File>();
        File[] filesAndDirs = aStartingDir.listFiles();
        List filesDirs = Arrays.asList(filesAndDirs);
        Iterator filesIter = filesDirs.iterator();
        File file = null;
        while (filesIter.hasNext()) {
            file = (File) filesIter.next();
            if (filter.accept(aStartingDir, file.getName())) {
                result.add(file); // always add, even if directory
            }
            if (!file.isFile()) {
                List<File> deeperList = getFilesRealWorking(file, filter);
                result.addAll(deeperList);
            }

        }
        return result;
    }
}

Related

  1. getFiles(final File directory, final FilenameFilter filter)
  2. getFiles(String name, FileFilter filter, boolean includeSubtree)
  3. getFiles(String sourceDirPath, FilenameFilter filter, Comparator comparator)
  4. getFiles(String sourceName, FilenameFilter filter)
  5. getFilesOnlyFilter()
  6. getFilesUnder(String path, FileFilter fileFilter)
  7. getFilesWithFilter(String DirectoryName, FilenameFilter Filter)