Search Filesystem While Approaching Root Directory
upward-matcher/  c
search-upward
search-upward/  first
directory-by-exact-name
file-by-exact-name
by-exact-name
7.4

Search Filesystem While Approaching Root Directory

Sage Gerard

Use this module to search for a specific file and/or directory where the search walks up directories until hitting the root of the associated filesystem.

value

upward-matcher/c : (-> directory-exists? (or/c path? #f))

A procedure that accepts a path to a directory D and returns a path indicating a matching directory or file in D, or #f if no match is found.

procedure

(search-upward include? [start])  (listof path?)

  include? : upward-matcher/c
  start : path? = (current-directory)
Apply include? to start, start/.., start/../.., and so on up until the applicable root directory. Returns a list of all paths from include?, ordered by number of path elements (descending).

Returns an empty list if no match is found.

> (search-upward
    (λ (base) (directory-exists? (build-path base "node_modules")))
    "/home/user/js-project/packageA/src/subpackageB")

'(#<path:/home/user/js-project/packageA/src/subpackageB/node_modules>

  #<path:/home/user/js-project/packageA/node_modules>

  #<path:/home/user/js-project/node_modules>)

procedure

(search-upward/first include? [start])  (or/c path? #f)

  include? : upward-matcher/c
  start : path? = (current-directory)
Like search-upward, except the search will stop on the first match and return the path for that match. Returns #f if there is no match at the applicable root directory.

procedure

(directory-by-exact-name name)  upward-matcher/c

  name : path-string?

procedure

(file-by-exact-name name)  upward-matcher/c

  name : path-string?

procedure

(by-exact-name name)  upward-matcher/c

  name : path-string?
Each of these procedures return an upward-matcher/c that checks if name exists in the given directory and is readable.