...
- Create some sample data for the above types.
- Write the templates for the above types.
- Develop a function
Code 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.
|
(empty line)
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 enter to see what it can do.
(empty line)
Use DrScheme's stepper to step through an example use of find?
. 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:
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.
|
(empty line)
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: Code 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.
|
Here are two pictorial examples, in both cases removing the directory
namedto-remove. These illustrate why this function can
return either a file or a list of files.
Example 1:
{{
foo
/ \ \
bar baz to-remove
/ \
one two
...