...
- Create some sample data for the above types.
- Write the templates for the above types.
- Develop a function
Note that this function is a vast simplification of{{find}}, the mother-of-all everything-but-the-kitchen-sink UNIX directory traversing command. If open a terminal window and enterCode Block ; find? : symbol file -> boolean ; Returns whether the filename is anywhere in the ; tree of files represented by the file. This includes both ; simple file names and directory names.
to see what it can do.Code Block man find
//
Use DrScheme's stepper to step through an example use offind?
. Following the templates leads to an overall strategy known as depth-first search, i.e., it explores each tree branch to the end before moving on to the next branch. - Develop the following function:
(empty line)Code Block ; any-duplicate-names? : file -> boolean ; Returns whether any (sub)directory directly or indirectly contains ; another directory or file of the same name. It does NOT check ; for duplicated names in separate branches of the tree.
There is a straightforward way to write this function that just follows the template.
(empty line) - Challenge: develop a program to check for duplicated names among
all directories and files in the given tree, not just subdirectories.
Here's a hint. Develop the following function:
Here are two pictorial examples, in both cases removing the directoryCode Block ; flatten-dir-once : symbol file -> (file or lof) ; Purpose: returns a structure like the original file, except that any (sub)directory with that name is removed and its contents are promoted up one level in the tree.
namedto-remove. These illustrate why this function can
return either a file or a list of files.
...