微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在公共 lisp 中将文件从一个目录复制到另一个目录的最简单方法?

如何解决在公共 lisp 中将文件从一个目录复制到另一个目录的最简单方法?

Moving a file seems easy,但是有没有一种简单的方法可以将给定路径中的文件复制到另一个路径?

解决方法

uiop package 有这样的功能:

(uiop:copy-file source-path target-path)

它是 ASDF 的一部分,因此它可能会立即用于某些 Common Lisp 实现。

,

虽然明智的答案是使用 ASDF 提供的东西,但您可以编写此内容。注意下面的代码没有经过非常仔细的测试(但我用它来复制二进制文件):

(defun copy-file (from to)
  ;; I'm sure there are now portability packages to do this but I do
  ;; not want to rely on them.  This is a naive implementation which
  ;; is not terrible.
  (with-open-file (out to :direction ':output
                       :if-exists ':supersede
                       :element-type '(unsigned-byte 8))
    (with-open-file (in from :direction ':input
                        :element-type '(unsigned-byte 8))
      (loop with buffer = (make-array 4096 :element-type '(unsigned-byte 8))
            for pos = (read-sequence buffer in)
            while (> pos 0)
            do (write-sequence buffer out :end pos)
            finally (return (values from to))))))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。