Please note, first of all, that this is a homework question, so I am not looking for a direct code or something like that, just so that someone can help me with my logic.
Assignment is performed in DrRacket. The question asks the question:
Given the file system, which we defined as a structure with two fields, the name and content, where the content is a list of either directories or files; write a function that will create the file name ".bak" for each file in the directory and place it immediately after the file.
I am completely lost. My logic is this: if the first in the content list is a file, just redo the directory with that file and add a new file with the addition of ".bak". This is as far as I can get - I canβt understand how to work if there is a subdirectory, or how to move further on the list.
Here is my awful code:
(define (backup my-fs) (cond [(empty? (dir-contents my-fs)) empty] [(file? (first (dir-contents my-fs))) (make-dir (dir-name my-fs) (append (backup-list (first (dir-contents my-fs)))(rest (dir-contents my-fs))))] [(dir? (first (dir-contents my-fs))) (backup (first (dir-contents my-fs)))]))
Can someone help me explain this?
source share