在common lisp中将文件从一个目录复制到另一个目录的最简单方法?
,但是否有一种简单的方法可以将给定路径中的文件复制到另一个路径?具有以下功能:在common lisp中将文件从一个目录复制到另一个目录的最简单方法?,lisp,common-lisp,Lisp,Common Lisp,,但是否有一种简单的方法可以将给定路径中的文件复制到另一个路径?具有以下功能: (uiop:copy-file source-path target-path) 它是ASDF的一部分,因此在一些常见的Lisp实现中可能会立即可用。虽然sane answeer要使用ASDF提供的东西,但您可以编写这个。注意:下面的代码没有经过非常仔细的测试(但我使用它来复制周围的二进制文件): 也可以从Lisp调用cp程序 (defun copy-file (from to) ;; I'm sure the
(uiop:copy-file source-path target-path)
它是ASDF的一部分,因此在一些常见的Lisp实现中可能会立即可用。虽然sane answeer要使用ASDF提供的东西,但您可以编写这个。注意:下面的代码没有经过非常仔细的测试(但我使用它来复制周围的二进制文件):
也可以从Lisp调用cp程序
(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))))))