findfiles_up
Prototype: findfiles_up(path, glob, level)
Return type: data
Description: Return a data array of files that match a given glob pattern by searching up the directory tree.
This function searches for files matching a given glob pattern glob in the
local filesystem by searching up the directory tree from a given absolute
path path. The function searches at most level levels of directories or
until the root directory is reached. Argument level defaults to inf if
not specified. The function returns a list of files as a data array where
the first element (element 0) and the last element (element N) is first
and last file or directory found respectively.
Note that glob patterns are not regular expressions. They match like Unix shells:
*matches any filename or directory at one level, e.g.*.cfwill match all files in one directory that end in.cfbut it won't search across directories.*/*.cfon the other hand will look two levels deep.**recursively matches up to six subdirectories.?matches a single letter.[abc]matchesa,borc.[!abc]matches any letters other thana,borc.[a-z]matches any letter fromatoz.[!a-z]matches any letter not fromatoz.{foo,bar}matchesfooorbar.
Arguments:
path:string- Path to search from - in the range:"?(/.*)glob:string- Glob pattern to match files - in the range:.+level:int- Number of levels to search - in the range:0,99999999999
Example:
bundle agent __main__
{
vars:
"path" # path to search up from
string => "/tmp/repo/submodule/some/place/deep/within/my/repo/";
"glob" # glob pattern matching filename
string => ".git/config";
"level" # how far to search
int => "inf";
"configs"
data => findfiles_up("$(path)", "$(glob)", "$(level)");
reports:
"Submodules '$(glob)' is located in '$(configs[0])'";
"Parents '$(glob)' is located in '$(configs[1])'";
}
Output:
R: Submodules '.git/config' is located in '/tmp/repo/submodule/.git/config'
R: Parents '.git/config' is located in '/tmp/repo/.git/config'
History:
- Introduced in 3.18.
- Brace expression (i.e.,
{foo,bar}) and negative bracket expressions (i.e.,[!abc]) were introduced in 3.24.
See also: findfiles().