Created
October 16, 2013 16:47
-
-
Save tobias/7011001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '[java.nio.file Path Files FileSystem FileSystems StandardCopyOption FileVisitor FileVisitResult]) | |
(defn ->path [path] | |
(if (instance? Path path) | |
path | |
(.getPath (FileSystems/getDefault) path (into-array String [])))) | |
(defn copy [from to] | |
(Files/copy (->path from) (->path to) (into-array [StandardCopyOption/COPY_ATTRIBUTES]))) | |
(defn copying-visitor [source dest] | |
(reify FileVisitor | |
(preVisitDirectory [_ dir _] | |
(copy dir (.resolve dest (.relativize source dir))) | |
FileVisitResult/CONTINUE) | |
(visitFile [_ file _] | |
(copy file (.resolve dest (.relativize source file))) | |
FileVisitResult/CONTINUE) | |
(postVisitDirectory [_ dir _] | |
FileVisitResult/CONTINUE))) | |
(defn copy-dir [source dest] | |
(let [source (->path source) | |
dest (->path dest)] | |
(Files/walkFileTree source (copying-visitor source dest)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment