Skip to content

Commit df9e484

Browse files
committed
Add glob capability to ls*
1 parent ba94f98 commit df9e484

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

project.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[overtone/at-at "0.2.1"]
1212
[overtone/osc-clj "0.7.1"]
1313
[overtone/byte-spec "0.3.1"]
14-
[overtone/midi-clj "0.2.1"]]
14+
[overtone/midi-clj "0.2.1"]
15+
[clj-glob "1.0.0"]]
1516
:dev-dependencies [[marginalia "0.2.0"]]
1617
:jvm-opts ["-Xms256m" "-Xmx1g" "-XX:+UseConcMarkSweepGC"])

src/overtone/helpers/file.clj

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
:author "Sam Aaron"}
44
overtone.helpers.file
55
(:use [clojure.java.io]
6-
[overtone.helpers.string]))
6+
[overtone.helpers.string])
7+
(:require [org.satta.glob :as satta-glob]))
78

89
(defn- files->abs-paths
910
"Given a seq of java.io.File objects, returns a seq of absolute paths for each
@@ -49,7 +50,11 @@
4950
"Given a path to a directory, returns a seq of java.io.File objects
5051
representing the directory contents"
5152
[path]
52-
(seq (.listFiles (file (resolve-abs-path path)))))
53+
(let [path (resolve-abs-path path)
54+
f (file path)]
55+
(if (.isDirectory f)
56+
(seq (.listFiles f))
57+
(satta-glob/glob path))))
5358

5459
(defn ls-paths
5560
"Given a path to a directory, returns a seq of strings representing the full
@@ -90,3 +95,11 @@
9095
[path]
9196
(let [files (filter #(.isDirectory %) (ls* path))]
9297
(files->names files)))
98+
99+
(defn glob
100+
"Given a glob pattern returns a seq of java.io.File instances which match.
101+
Ignores dot files unless explicitly included.
102+
103+
Examples: (glob \"*.{jpg,gif}\") (glob \".*\") (glob \"/usr/*/se*\")"
104+
[pattern]
105+
(satta-glob/glob pattern))

0 commit comments

Comments
 (0)