Java Directory to File List getAllFilesByProfix(String path, String suffix, List files)

Here you can find the source of getAllFilesByProfix(String path, String suffix, List files)

Description

get All Files By Profix

License

Apache License

Declaration

public static void getAllFilesByProfix(String path, String suffix, List<File> files) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.util.List;

public class Main {
    public static void getAllFilesByProfix(String path, String suffix, List<File> files) {
        File file = new File(path);
        if (file.isDirectory()) {
            File[] fs = file.listFiles();
            if (fs != null) {
                for (File file2 : fs) {
                    if (file2.isDirectory()) {
                        getAllFilesByProfix(file2.getPath(), suffix, files);
                    } else {
                        if (suffix != null) {
                            if (file2.toString().endsWith(suffix)) {
                                files.add(file2);
                            }//from w  w w  .  j a  v a  2  s  .  co m
                        } else {
                            files.add(file2);
                        }
                    }
                }
            }

        } else {
            if (suffix != null) {
                if (file.toString().endsWith(suffix)) {
                    files.add(file);
                }
            } else {
                files.add(file);
            }
        }
    }
}

Related

  1. getAllFiles(String path, boolean isDepth)
  2. getAllFiles(String sDirectoryPath)
  3. getAllFiles(String zipName, String fileNameRegEx)
  4. getAllFiles(String[] args, boolean recurse)
  5. getAllFilesByExtension(String path, String extension)
  6. getAllFilesEndingWith(String path, final String extension)
  7. getAllFilesEndingWith(String path, final String extension)
  8. getAllFilesForType(File dir, FilenameFilter filter)
  9. getAllFilesFromDir(File dir)