views:

98

answers:

2

Is there an easy way to get a list of files matching a specified filemask? By filemask I mean classic wildcard, not regexp.

I can use file-seq and then filter with regexp created from a wildcard. However, it is not trivial (consider escaping etc.)

I am also aware of FilenameUtils.wildcardMatch() from Apache Commons, but I'm reluctant to add such a dependency for a tiny tool I'm building.

There must exist something in the Clojure ecosystem I am not aware of.

+4  A: 

I'm not aware of any such tool written in Clojure.

java.nio.file.PathMatcher can do wildcard matching, see http://download.oracle.com/javase/tutorial/essential/io/find.html

Stuart Sierra
+4  A: 

clj-glob fits the bill: http://github.com/jkk/clj-glob

It may or may not be production-ready depending on your needs (e.g., hasn't been fully tested with Windows), but it has worked well for my purposes.

P.S., patches welcome.

Justin Kramer
This is exactly what I was looking for. I fixed the code to work on Windows - please consider pulling.
qertoip