clojure - How to substitute path to home for "~"? -
clojure - How to substitute path to home for "~"? -
if pass in path command line, "~" expands home directory:
(defn -main "i don't whole lot ... yet." [& args] (doseq [arg args] (println arg))) britannia:uberjar srseverance$ java -jar args-0.1.0-snapshot-standalone.jar ~/158.clj /volumes/macintosh hd/users/srseverance/158.clj
but if seek utilize path-file containing ~, can't find file.
user> (with-open [r (clojure.java.io/reader "~/158.clj")] (doall (line-seq r))) filenotfoundexception ~/158.clj (no such file or directory) java.io.fileinputstream.open0 (fileinputstream.java:-2)
how take string like, "~/158.clj" , clojure.java.io/reader
can use, such "/volumes/macintosh hd/users/srseverance/158.clj"?
you can define
(defn expand-home [s] (if (.startswith s "~") (clojure.string/replace-first s "~" (system/getproperty "user.home")) s))
and utilize resolve home directory:
(clojure.java.io/reader (expand-home "~/158.clj"))]
you fs library definition of expand-home
clojure
Comments
Post a Comment