(define-struct dir (name contents)) (defile (file? any) (symbol? any)) ;;;;;;;;;;;;;;;;;;;;;;;; ; flatten-dir : directory symbol -> (directory or l-o-d-f) ; removes the named subdirectory, moving its contents up one level (define (flatten-dir a-dir name) (cond [(symbol=? (dir-name a-dir) name) (dir-contents a-dir)] [else (make-dir (dir-name a-dir) (flatten-dir-in-lodf (dir-contents a-dir) name))])) ; flatten-dir-in-lodf : l-o-d-f symbol -> l-o-d-f ; removes the named subdirectory, moving its contents up one level (define (flatten-dir-in-lodf a-lodf name) (cond [(empty? a-lodf) empty] [(file? (first a-lodf)) (cons (first a-lodf) (flatten-dir-in-lodf (rest a-lodf) name))] [(dir? (first a-lodf)) (flatten-helper (flatten-dir (first a-lodf) name) (flatten-dir-in-lodf (rest a-lodf) name))])) ; flatten-helper : (directory or l-o-d-f) l-o-d-f -> l-o-d-f ; combines (an item or list) and a list into a new list (define (flatten-helper a-dir-or-lodf a-lodf) (cond [(dir? a-dir-or-lodf) (cons a-dir-or-lodf a-lodf)] [else (append a-dir-or-lodf a-lodf)]))