Robert Campbell napisaƂ(a):
> I'm trying to write a file scanner very similar to the one on page 131
> of Stuart's book:
>
> (ns user
>   (:use [clojure.contrib.duck-streams :only [reader]]))
>
> (defn scan [dir]
>   (for [file (file-seq dir)]
>     (with-open [rdr (reader file)]
>       (count (filter #(re-find #"foobar" %) (line-seq rdr))))))
>
> user> (scan (java.io.File. "C:/SomeValidDir"))
>
> java.lang.RuntimeException: java.io.FileNotFoundException:
> C:\publishing\cosmos\trunk\web (Access is denied) (NO_SOURCE_FILE:0)
>
> The strange part:
>
> user> (file-seq (java.io.File. "C:/SomeValidDir"))
> ( #<File C:\SomeValidDir\foo1.clj> #<File C:\SomeValidDir\foo2.clj>)
> and so on, properly listing the entire contents of the directory.
>
> user> (for [file (file-seq (java.io.File.
> "C:/publishing/cosmos/trunk/web"))] nil)
> (nil nil) and so on, again working properly.
>
> user> (for [file (file-seq (java.io.File.
> "C:/publishing/cosmos/trunk/web"))] (with-open [rdr (reader file)]
> nil))
> ; Evaluation aborted. (this one finally fails with the same error)
>
> So "with-open [rdr (reader file)]" is the problem, but why?

I guess "reader" does not work for directories. Try to change your
"for" loop like this:
(for [file (file-seq dir) :when (.isFile file)]

HTH,
Rob

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to