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:
- Create directories within directories (as many layers as you want).
- Create text files in some of these directories while leaving some directories empty for more excitement.
How to do it...
- We are going to create a
static
method that takes aFile
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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.