glob
Match paths against shell-style patterns like src/**/*.brass, and find the files on disk that match one.
| Pattern | Matches |
|---|---|
* |
any run of characters within one name |
? |
one character within one name |
[a-z], [!x] |
one character in, or not in, the set |
** |
any number of folders, including none |
\* |
a literal * |
* and ? never match /. A name starting with . is matched only by a pattern part that starts with . too, so * skips hidden files. ** is the exception: it crosses hidden folders too, so **/*.txt matches .git/a.txt.
Check one path
Section titled “Check one path”import glob
print(glob.matches("src/**/*.brass", "src/main.brass"))print(glob.matches("src/**/*.brass", "src/lib/deep/util.brass"))print(glob.matches("*.txt", "notes/a.txt"))print(glob.matches("*", ".hidden"))truetruefalsefalseFind files
Section titled “Find files”find takes an fs.Files permission and returns the matching paths, sorted. A relative pattern is searched from the current folder.
import fsimport glob
let dir = try fs.temp_dir()try fs.create_dir_all(&dir.join("src/lib"))try fs.write(&dir.join("src/main.brass"), "")try fs.write(&dir.join("src/lib/util.brass"), "")try fs.write(&dir.join("src/notes.txt"), "")let base = dir.path()for p in try glob.find(&fs.files(), &(base + "/src/**/*.brass")) { print(p.slice(base.len() + 1, p.len()))}src/lib/util.brasssrc/main.brassReference
Section titled “Reference”import globFunctions
Section titled “Functions”matches
Section titled “matches”pub fn matches(pattern: &Str, path: &Str) -> bool* and ? stay within one name, [a-z]/[!x] match one character, and ** spans folders.
match_name
Section titled “match_name”pub fn match_name(pattern: &Str, name: &Str) -> boolA name starting with . is matched only by a pattern that starts with . too.
Matches one name, with no / handling. matches uses it for each part of a path.
pub fn find(files: &fs.Files, pattern: &Str) -> Vec<Str> ! fs.IoErrorThe paths matching pattern, sorted; the search starts below its folders without wildcards.
The search starts in the longest leading part of the pattern without wildcards (src in src/**/*.brass), so a pattern with a fixed folder does not walk the whole tree. Folders are matched as well as files: src/* lists both.