Retrieving all filenames from hierarchical directories using Java

This recipe (and the following) is for the data scientist who wants to retrieve the file paths and names (for some future analysis) from a complex directory structure that contains numerous directories and files inside a root directory.

Getting ready

In order to perform this recipe, we will require the following:

  1. Create directories within directories (as many layers as you want).
  2. Create text files in some of these directories while leaving some directories empty for more excitement.

How to do it...

  1. We are going to create a static method that takes a File argument, which is eventually the root directory or the directory to start with. The method will return a set of files that are found ...

Get Java Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.