[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copying directories



>Is there a predefined function in MCL (any version) that
>copies the whole contents of a directory? Same as COPY-FILE
>but for directories...

It would probably be cleaner to do this with Common Lisp's pathname
functions, but they always confuse me...

(defun copy-directory (from-dir to-dir &key 
                                (if-exists :error)
                                verbose)
  (let* ((mac-from-dir (mac-namestring from-dir))
         (mac-to-dir (mac-namestring to-dir))
         (mac-from-dir-length (length mac-from-dir))
         (did-one nil))
    (flet ((require-directory (string original)
             (unless (eql #\: (char string (1- (length string))))
               (error "~s is not a directory" original))))
      (require-directory mac-from-dir from-dir)
      (require-directory mac-to-dir to-dir))
    (dolist (from-file (directory (concatenate 'string mac-from-dir "**:*")))
      (let* ((namestring (mac-namestring from-file))
             (to-file (concatenate 'string
                                   mac-to-dir
                                   (subseq namestring
                                           mac-from-dir-length
                                           (length namestring)))))
        (when verbose
          (format t "~&Copying ~s to ~s..." from-file to-file)
          (setq did-one t))
        (copy-file from-file to-file :if-exists if-exists)))
    (when did-one (terpri))))