Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1.  
  2. public class Main {
  3.  
  4.     private static ArrayList<File> getAllImages(String basePath) {
  5.         ArrayList<File> filesList = new ArrayList<File>();
  6.         getAllFilesHelper(basePath, filesList);
  7.         return filesList;
  8.     }
  9.  
  10.  
  11.     private static void getAllFilesHelper(String directoryName, List<File> files) {
  12.         File directory = new File(directoryName);
  13.         // Get all the files from a directory.
  14.         File[] fList = directory.listFiles();
  15.         if (fList == null)
  16.             return;
  17.         for (File file : fList) {
  18.             if (file.isFile()) {
  19.                 files.add(file);
  20.             } else if (file.isDirectory()) {
  21.                 getAllFilesHelper(file.getAbsolutePath(), files);
  22.             }
  23.         }
  24.     }
  25.  
  26.     public static void main(String[] args) {
  27.     System.out.println("Hello again!");
  28.     // will print paths of all files in folder and subfolders
  29.     System.out.println(getAllImages("C:\\temp"));
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement