Created
November 4, 2010 15:54
-
-
Save drankard/662680 to your computer and use it in GitHub Desktop.
Some general filesystem crawler functions
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
(ns order.docs | |
(:import java.io.File) | |
(:import java.io.FileNotFoundException)) | |
(defn as-file [s] | |
"Return whatever we have as a java.io.File object" | |
(cond (instance? File s) s ; already a file, return unchanged | |
(string? s) (File. s) ; return java.io.File for path s | |
:else (throw (FileNotFoundException. (str s))))) | |
(defn walk [^File dir] | |
(let [children (.listFiles dir) | |
subdirs (filter #(.isDirectory %) children) | |
files (filter #(.isFile %) children)] | |
(concat files (mapcat walk subdirs)))) | |
; A usage method | |
(defn get-markdown-files [dir] | |
(filter #(.endsWith % ".md") (map #(.toString %) (walk (as-file "public"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment