Java Directory to File List getAllFilesInFolder(String folder)

Here you can find the source of getAllFilesInFolder(String folder)

Description

get All Files In Folder

License

Open Source License

Declaration

public static String[] getAllFilesInFolder(String folder) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static String[] getAllFilesInFolder(String folder) {
        File file = load(folder);
        if (file != null) {
            if (file.exists()) {
                if (file.isDirectory()) {
                    File[] fileList = file.listFiles();
                    String[] fileNames = new String[fileList.length];
                    for (int i = 0; i < fileNames.length; i++) {
                        fileNames[i] = fileList[i].getName();
                    }/*from w w w  .ja  va2  s  . c o m*/
                    return fileNames;
                }
            }
        }
        return new String[] {};
    }

    public static File load(String filePath) {
        File file = new File(filePath);
        if (file.exists()) {
            return file;
        }
        return null;
    }

    public static boolean isDirectory(String filePath) {
        File file = load(filePath);
        if (file != null) {
            return file.isDirectory();
        }
        return false;
    }
}

Related

  1. getAllFilesInDirectory(String directoryPath)
  2. getAllFilesInDirectory(String dirName)
  3. getAllFilesInDirectory(String path)
  4. getAllFilesInDirMatchingPattern(String directory, final String regex, final boolean first_match2)
  5. getAllFilesInFolder(File rootFolder, FileFilter filter, int maxFilesRequired)
  6. getAllFilesInFolderAndSubFolders(String folder)
  7. getAllFilesInHierarchy(final String basePath, final FilenameFilter filter)
  8. getAllFilesInSubFolder(String base, String ending)
  9. getAllFilesInternal(final File aPath, final FilenameFilter filter, final List fileList)