Java Directory to File List getAllFiles(String sDirectoryPath)

Here you can find the source of getAllFiles(String sDirectoryPath)

Description

Returns the set of all files in the given directory

License

Open Source License

Parameter

Parameter Description
sDirectoryPath The directory path <p>

Return

The required list of files

Declaration

private static String[] getAllFiles(String sDirectoryPath) 

Method Source Code


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

import java.io.File;

public class Main {
    /**//from   w  w  w  .  ja va 2s .c o m
     * Returns the set of all files in the given directory
     * <p>
     * 
     * @param sDirectoryPath
     *            The directory path
     *            <p>
     * @return The required list of files
     */
    private static String[] getAllFiles(String sDirectoryPath) {

        if (sDirectoryPath == null) {
            return new String[0];
        }

        File fileThisDirectory = new File(sDirectoryPath);

        if (fileThisDirectory.isDirectory() == false) {
            return new String[0];
        } else {
            String[] asFileList = fileThisDirectory.list();
            if (asFileList == null || asFileList.length == 0) {
                return asFileList;
            }
            return asFileList;
        }
    }
}

Related

  1. getAllFiles(String directory)
  2. getAllFiles(String dirPath)
  3. getAllFiles(String folderPath)
  4. getAllFiles(String path)
  5. getAllFiles(String path, boolean isDepth)
  6. getAllFiles(String zipName, String fileNameRegEx)
  7. getAllFiles(String[] args, boolean recurse)
  8. getAllFilesByExtension(String path, String extension)
  9. getAllFilesByProfix(String path, String suffix, List files)