How can we list all files and folders recursively?

Nam G VU

As search via google, and in this SO site, results will come up with FileUtils.listFilesAndDirs() method from Apache Commons IO.

But this method is not going recursively into sub folders - we need recursive file listing.

How can we do it with Commons IO?

P.S.:

A native way to do it is using File.listFiles() natively supported by JDK as solved here.

Strikeskids

You can use the FileUtils.listFiles(File base, String[] extensions, boolean recursive).

To retrieve all of the files set recursive to true and extensions to null.

 FileUtils.listFiles(basePath, null, true);

Alternatively, using the other overides of FileUtils.listFiles, you can provide more detailed search parameters.

If you want to find both files AND directories instead of only files, use the

 FileUtils.listFilesAndDirs(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)

See here for more detail.

  • The dirFilter argument sets which directories the search will recurse on. To recurse on all subdirectories use TrueFileFilter.INSTANCE. To NOT recurse at all, just base null.

  • The fileFilter arguments chooses the files and directories the search will return. To return all of them, use TrueFileFilter.INSTANCE.

Example call

FileUtils.listFilesAndDirs(basePath, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Recursively set all files and folders to 777 from this list

From Dev

How to list files and folders recursively and separately with Boost and C++

From Dev

How to recursively remove all but list of files?

From Dev

How to recursively list all hidden files and directories?

From Dev

How to list all the folders and its files in php

From Dev

How to show list all folders not files in path

From Dev

zip all files and folders recursively in bash

From Dev

How do I compare two folders recursively and generate a list of files and folders that are different?

From Dev

How can you in Java list all files recursively in a folder that do not match an array of extensions?

From Dev

How can I recursively list Md5sum of all the files in a directory and its subdirectories?

From Dev

How can I list all files and folders beyond a specified size limit?

From Dev

How to rename folders and files recursively in MacOS

From Dev

How to recursively list all files of desired file type in a specified directory?

From Dev

How to recursively remove all empty folders in PowerShell?

From Dev

How can we count/list all files opened by a specific program/COMMAND?

From Dev

Recursively import all .py files from all folders

From Dev

rsync all files recursively - exclude all folders (but not their contents)

From Dev

How to use ZipFile Class in Java to recursively open all files including those under Folders

From Dev

How to use ZipFile Class in Java to recursively open all files including those under Folders

From Dev

(Batch) How to recursively delete all files/folders in a directory except those with a leading .?

From Dev

How can I move all files in subdirectories recursively to a single directory?

From Dev

How can I recursively delete all empty files and directories in Linux?

From Dev

How can I move all files in subdirectories recursively to a single directory?

From Dev

How can I recursively change the permissions of specific files into a list of directories?

From Dev

How can i move all files and folders from multiple directories?

From Dev

How can i move all files and folders from multiple directories?

From Dev

Recursively deleting all files and folders from a given FTP path

From Dev

Printing all files and folders in a path in Linux, recursively, in C

From Dev

Recursively rename all files and folders to Title Case from terminal

Related Related

  1. 1

    Recursively set all files and folders to 777 from this list

  2. 2

    How to list files and folders recursively and separately with Boost and C++

  3. 3

    How to recursively remove all but list of files?

  4. 4

    How to recursively list all hidden files and directories?

  5. 5

    How to list all the folders and its files in php

  6. 6

    How to show list all folders not files in path

  7. 7

    zip all files and folders recursively in bash

  8. 8

    How do I compare two folders recursively and generate a list of files and folders that are different?

  9. 9

    How can you in Java list all files recursively in a folder that do not match an array of extensions?

  10. 10

    How can I recursively list Md5sum of all the files in a directory and its subdirectories?

  11. 11

    How can I list all files and folders beyond a specified size limit?

  12. 12

    How to rename folders and files recursively in MacOS

  13. 13

    How to recursively list all files of desired file type in a specified directory?

  14. 14

    How to recursively remove all empty folders in PowerShell?

  15. 15

    How can we count/list all files opened by a specific program/COMMAND?

  16. 16

    Recursively import all .py files from all folders

  17. 17

    rsync all files recursively - exclude all folders (but not their contents)

  18. 18

    How to use ZipFile Class in Java to recursively open all files including those under Folders

  19. 19

    How to use ZipFile Class in Java to recursively open all files including those under Folders

  20. 20

    (Batch) How to recursively delete all files/folders in a directory except those with a leading .?

  21. 21

    How can I move all files in subdirectories recursively to a single directory?

  22. 22

    How can I recursively delete all empty files and directories in Linux?

  23. 23

    How can I move all files in subdirectories recursively to a single directory?

  24. 24

    How can I recursively change the permissions of specific files into a list of directories?

  25. 25

    How can i move all files and folders from multiple directories?

  26. 26

    How can i move all files and folders from multiple directories?

  27. 27

    Recursively deleting all files and folders from a given FTP path

  28. 28

    Printing all files and folders in a path in Linux, recursively, in C

  29. 29

    Recursively rename all files and folders to Title Case from terminal

HotTag

Archive