The goal of this lab is to practice using recursion to interact with recursively structured data. One example of a recursively structured collection is the file system of a computer. A file system is made up of directories, each of which may contain additional directories.
This short video describes the basic recursive algorithm for searching a file system: Algorithms: Recursion
The following files are provided:
DirectorySearcher.java This
(unfinished) class is responsible for recursively traversing a
directory tree starting from a designated directory.
DirectoryDriver.java
This is a driver class for executing the methods provided
by DirectorySearcher. As it is currently written it uses
a DirectorySearcher to list the contents of the current
directory. listDirectories method of the
DirectorySearcher class. Test your finished method by
modifying the driver so that it calls this method instead
of listDirectory.
Your solution should print a "/" after each directory name and indent the files four spaces under each directory.
For example, if the starting path is "../PA1", the output might look like this:
PA1/
bin/
Letter.class
Hand.class
LetterTest.class
Board.class
PlayScrabble.class
BoardTest.class
HandTest.class
.project
.settings/
org.eclipse.jdt.core.prefs
.classpath
src/
LetterTest.java
HandTest.java
Letter.java
PlayScrabble.java
Board.java
BoardTest.java
Hand.java
Complete the searchDirectories method of the DirectorySearcher class.
Test your method by modifying the driver; search for different patterns to make sure it works.
Your solution should print the path to each file that is found.
(Just print the File object itself, rather than calling getName.)
For example, if the search string "Board", the output might look like this:
../PA1/bin/Board.class ../PA1/bin/BoardTest.class ../PA1/src/Board.java ../PA1/src/BoardTest.java
Submit your completed DirectorySearcher.java file via Autolab.