Android Directory Search find(File pDirectory, String pRegex)

Here you can find the source of find(File pDirectory, String pRegex)

Description

find all files in pDirectory and its sub directories whose absolute path matches pRegex

License

Apache License

Parameter

Parameter Description
pDirectory a parameter
pRegex a parameter

Declaration

public static synchronized Vector<File> find(File pDirectory,
        String pRegex) 

Method Source Code

/**/*from w w  w  . j a  va  2  s .c om*/
 Copyright 2014 Jens Glufke

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 * -----------------------------------------------------------------------<br>
 * 
 * class that can be used to operations on files like copy, deleteDir etc 
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public class Main{
    /**
     * 
     * find a file in pDir and its sub directories that matches pFilter
     * @param pFoundFiles
     * @param pDir
     * @param pFilter
     * @return
     *
     */
    public static Vector<File> find(Vector<File> pFoundFiles, File pDir,
            FileFilter pFilter) {
        if (pDir.isDirectory()) {
            File[] lFoundFiles = pDir.listFiles(pFilter);
            if (lFoundFiles != null && lFoundFiles.length > 0) {
                pFoundFiles.addAll(Arrays.asList(lFoundFiles));
            }
            for (File lFile : pDir.listFiles()) {
                find(pFoundFiles, lFile, pFilter);
            }
        }
        return pFoundFiles;
    }
    /**
     * find all files in pDirectory and its sub directories whose absolute path
     * matches pRegex
     * @param pDirectory
     * @param pRegex
     * @return
     */
    public static synchronized Vector<File> find(File pDirectory,
            String pRegex) {
        Vector<File> lReturn = new Vector<File>();
        lReturn = find(lReturn, pDirectory, new RegExpFileFilter(pRegex));
        return lReturn;
    }
}

Related

  1. findFiles(File dir, FileFilter filter)
  2. recursiveSearch(java.io.File dir, String fileName)