Brandon Barret writes: > Hello all, > > I am working on a program that needs to list all the files in a directory. > I have read that Clojure doesn't yet have great support for this kind of > task, and that it is better to import java.io.File to your namespace in > order to use some of it's methods. Every time I have done this in Eclipse, > I get the same error: > > "No matching field found: getName for class java.lang.String (files.clj:0)" > > My question: Is this a "me" problem, perhaps a syntax error, a java > problem, or a Clojure problem? I have used java for quite a while, and > think that I am importing the class correctly: > > (import 'java.io.File), or should I just be using > Clojure.java.io....confused in this case.
Do you want to *recursively* list all files in the directory? If so, take a look at `file-seq': http://clojuredocs.org/clojure_core/clojure.core/file-seq Passed a java.io.File pointing to a directory, it gives you a sequence of file objects in it and all its subdirectories. To get a list of all files ending in .jar in the current directory: (filter #(.endsWith (str %) ".jar") (file-seq (java.io.File. "."))) -- Moritz Ulrich
pgpGoeDqLQ_Op.pgp
Description: PGP signature