I call a java function in Clojure to get a list of files.
(require '[clojure.java.io :as io])
(str (.listFiles (io/file "/home/loluser/loldir")))
And I get a whole bunch of strings like these
#<File /home/loluser/loldir/lolfile1>
etc. How do I get rid of the brackets and put them in some form of an array so another function can access it?
Those strings are just the print format for a Java File
object.
See the File javadoc for which operations are available.
If you want the file paths as strings, it would be something like
(map #(.getPath %)
(.listFiles (io/file "/home/loluser/loldir")))
Or you could just use list
, which returns strings in the first place:
(.list (io/file "/home/loluser/loldir"))
If you want to read the file, you might as well keep it as a File object to pass into the core slurp
or other clojure.java.io or clojure.contrib.duck-streams functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With