Java Directory to File List getAllFilesInDirectory(String path)

Here you can find the source of getAllFilesInDirectory(String path)

Description

Returns the entire contents of a folder.

License

Open Source License

Declaration

public static File[] getAllFilesInDirectory(String path) 

Method Source Code

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

import java.io.File;

public class Main {
    /**//from   w  ww. ja va 2 s  .c o m
    * Returns the entire contents of a folder. Returns NULL if no files exist.
    */
    public static File[] getAllFilesInDirectory(String path) {
        File folder = new File(path);
        if (folder.exists()) {
            return folder.listFiles();
        }
        return null;
    }

    public static boolean exists(String path, String fileNameWithoutFullPath) {
        String filePath = getFileNameWithPath(path, fileNameWithoutFullPath);
        return exists(filePath);
    }

    public static boolean exists(String fileNameWithFullPath) {
        File file = new File(fileNameWithFullPath);
        return file.exists();
    }

    public static String getFileNameWithPath(String path, String fileNameWithoutFullPath) {
        return path + File.separator + fileNameWithoutFullPath;
    }
}

Related

  1. getAllFilesInDir(boolean traverseSubDirs, File dir, boolean includeHidden, String prefix)
  2. getAllFilesInDirectory(File dir)
  3. getAllFilesInDirectory(File directory, List files)
  4. getAllFilesInDirectory(String directoryPath)
  5. getAllFilesInDirectory(String dirName)
  6. getAllFilesInDirMatchingPattern(String directory, final String regex, final boolean first_match2)
  7. getAllFilesInFolder(File rootFolder, FileFilter filter, int maxFilesRequired)
  8. getAllFilesInFolder(String folder)
  9. getAllFilesInFolderAndSubFolders(String folder)