Java File List Load getFileList(String path, String searchString)

Here you can find the source of getFileList(String path, String searchString)

Description

Returns the fileList.

License

Apache License

Parameter

Parameter Description
path a parameter
searchString a parameter

Return

Vector

Declaration

public static Vector<File> getFileList(String path, String searchString) 

Method Source Code


//package com.java2s;
/*/*  www . j a  va 2 s  .com*/
* Copyright 2012 the original author or authors.
*
* 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.
*/

import java.io.File;

import java.util.Collections;
import java.util.Vector;

public class Main {
    /**
     * Returns the fileList.
     * 
     * @author nKarakus
     * @param path
     * @param searchString
     * @return Vector<File>
     */
    public static Vector<File> getFileList(String path, String searchString) {
        Vector<File> fileList = new Vector<File>();
        File dir = new File(path);
        File[] files = dir.listFiles();

        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                if (files[i].getName().contains(searchString)) {
                    fileList.add(files[i]);
                }
            }
            Collections.sort(fileList);
            return fileList;
        }
        return null;
    }
}

Related

  1. getFileList(String path)
  2. getFileList(String path)
  3. getFileList(String path)
  4. getFileList(String path, String filterName)
  5. getFileList(String path, String regex)
  6. getFileList(String s)
  7. getFileList(String zipFilePath)
  8. getFileListByDFS(File file)
  9. getFileListByExtension(final String location, final String extension)