您可以使用以下代码copy-dir:
复制目录(从到复制目录)
将目录从 复制
from到to. 如果to已存在,则将该目录复制到与from该to目录内同名的目录中。
(defn copy-dir
"Copy a directory from `from` to `to`. If `to` already exists, copy the directory
to a directory with the same name as `from` within the `to` directory."
[from to]
(when (exists? from)
(if (file? to)
(throw (IllegalArgumentException. (str to " is a file")))
(let [from (file from)
to (if (exists? to)
(file to (base-name from))
(file to))
trim-size (-> from str count inc)
dest #(file to (subs (str %) trim-size))]
(mkdirs to)
(dorun
(walk (fn [root dirs files]
(doseq [dir dirs]
(when-not (directory? dir)
(-> root (file dir) dest mkdirs)))
(doseq [f files]
(copy+ (file root f) (dest (file root f)))))
from))
to))))
Run Code Online (Sandbox Code Playgroud)