Java Folder Read getFilesByPath(String toDir)

Here you can find the source of getFilesByPath(String toDir)

Description

get all file in a folder

License

Open Source License

Parameter

Parameter Description
toDir a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static List getFilesByPath(String toDir) throws Exception 

Method Source Code

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

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  w  w  w.  ja  va  2  s  .co m*/
     * get all file in a folder
     * @param toDir
     * @return
     * @throws Exception
     */
    public static List getFilesByPath(String toDir) throws Exception {
        List fileList = new ArrayList();
        File dir = new File(toDir);
        File[] files = dir.listFiles();
        String podOrderDir = toDir;
        System.out.println(podOrderDir);
        System.out.println("size:" + files.length);
        for (int i = 0; i < files.length; i++) {

            if (files[i].isDirectory()) {
                podOrderDir = files[i].getPath();
                fileList.addAll(getFilesByPath(podOrderDir));
            } else {
                fileList.add(toDir + File.separator + files[i].getName());
            }
        }

        return fileList;
    }
}

Related

  1. getFilesAndFilesSubDirectories(String directoryName, String regexPattern)
  2. getFilesArray(File baseStorePath, final String fileNameSearchPattern)
  3. getFilesAsArrayList(String path)
  4. getFilesByDate(String directory, final boolean earliestFirst)
  5. getFilesByName(File path, String name)
  6. getFilesByRegxFileName(String dir, final String regxName)
  7. getFilesByType(String fileType, String path)
  8. getFilesByType(String path, final String type)
  9. getFilesCannotAccess(File... files)