;; A disk-entry is: ;; - a filename, or ;; - a directory-name, or ;; - a linkname. ;; ;; A filename is a pathname. ;; A directory-name is a pathname. ;; A linkname is a pathname. ;; A pathname is a string. ;; directory-list-fullname: pathname --> list of pathname ;; Like directory-list, except that we use build-path to return ;; a full pathname rather than just the name of the entry inside the directory. ;; (define (directory-list-fullname f) (map (lambda (x) (build-path f x)) (directory-list f))) ;; WARNING: these next functions change the disk! ;; backup-disk-entry: item --> list of string-or-false ;; (define (backup-disk-entry de old-suffix new-suffix) (cond [(file-exists? de) (backup-file de old-suffix new-suffix)] [(directory-exists? de) (map (lambda (sub-de) (backup-disk-entry sub-de old-suffix new-suffix)) (directory-list-fullname de))] [(link-exists? de) empty] ; A link that's not a file or dir is a dangling/circular link! [else (error 'backup-disk-entry "Hmmm, ~a is not a known type of disk-entry!" de)])) ; Note that this "map" is doing the work of calling backup-disk-entry on everything in the de. ; The use of "lambda" is needed only because map takes single-argument functions, ; whereas backup-disk-entry needs three; the lambda provides the other two arguments. ; This could also have been effected with local, rather than lambda. ;; backup-file: filename --> string or false ;; (define (backup-file fname old-suffix new-suffix) (cond [(has-suffix? fname old-suffix) (local {(define new-fname (string-append (remove-suffix fname old-suffix) new-suffix))} (cond [(not (file-exists? new-fname)) (copy-file fname new-fname)] [else false]))] [else false])) (backup-disk-entry (build-path (current-directory) "comp210") ".scm" ".ss")