Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of files matching a filemask (wildcard) in Clojure?

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.

like image 649
qertoip Avatar asked Aug 06 '10 19:08

qertoip


2 Answers

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.

like image 157
Justin Kramer Avatar answered Sep 28 '22 02:09

Justin Kramer


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

like image 39
Stuart Sierra Avatar answered Sep 28 '22 00:09

Stuart Sierra