Good day. The task is as follows. At the entrance serves a specific directory. You need to get a list of all files and save it to the list. The catalog can contain subdirectories, subdirectories in subdirectories, etc. I think the point is clear. The output should be an ordinary file list (the full path to the file is displayed) without nested directories. Tell me how you can solve this problem. Thank you in advance.

  • And what exactly did you fail? - pavel
  • I can't figure out how to do it recursively yet - Kostya Nyrchenko
  • You can get a list of files from the directory. Further for (File file : dir) if (file.isDir()) findRec(file); else LIST.add(file.getFullName()); for (File file : dir) if (file.isDir()) findRec(file); else LIST.add(file.getFullName()); - pavel

1 answer 1

 List<File> files = (List<File>) FileUtils.listFiles(dir, null, true); for (File file : files) { System.out.println("file: " + file.getCanonicalPath()); } file: C:\projects\workspace\testing\dir\anotherdir\hamburger.jsp file: C:\projects\workspace\testing\dir\anotherdir\test2.txt file: C:\projects\workspace\testing\dir\test1.txt