Skip to content

Instantly share code, notes, and snippets.

@dpsutton
Last active July 31, 2022 07:41
Show Gist options
  • Save dpsutton/6d6a452dc3386831506eac4ac648f859 to your computer and use it in GitHub Desktop.
Save dpsutton/6d6a452dc3386831506eac4ac648f859 to your computer and use it in GitHub Desktop.
(reify FileVisitor
(visitFile [_ p attrs]
(let [f (.relativize src p)
last-mod (Files/getLastModifiedTime p (make-array LinkOption 0))]
(when *verbose* (println (str (.toString src) "/" (.toString f))))
(with-open [is (Files/newInputStream p (make-array OpenOption 0))]
(copy! (.toString f) is (.resolve dest (.toString f)) last-mod)))
FileVisitResult/CONTINUE)
(preVisitDirectory [_ p attrs]
(Files/createDirectories (.resolve dest (.toString (.relativize src p)))
(make-array FileAttribute 0))
FileVisitResult/CONTINUE)
(postVisitDirectory [_ p ioexc]
(if ioexc (throw ioexc) FileVisitResult/CONTINUE))
(visitFileFailed [_ p ioexc] (throw (ex-info "Visit File Failed" {:p p} ioexc))))
(Files/walkFileTree src visit-opts Integer/MAX_VALUE copy-dir)
(java.nio.file.Files/walkFileTree
(java.nio.file.Paths/get "/Users/dan/projects/clojure/clojure/src/clj/clojure/java"
(into-array String []))
(proxy [java.nio.file.SimpleFileVisitor] []
(preVisitDirectory [dir _]
(println "directory" dir)
java.nio.file.FileVisitResult/CONTINUE)
(visitFile [file _]
(println file)
java.nio.file.FileVisitResult/CONTINUE)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment