Buck: glob()

glob()

The glob() function is used to specify a set of files using patterns. A pattern should be structured as a relative path with no repeated or trailing separators (/). Patterns may contain shell-like wildcards *, ?, [charset]. Additionally, a path element ** will match any subpath. For instance foo/**/bar is equivalent to ["foo/bar", "foo/*/bar", "foo/*/*/bar", ...].

Arguments

  • The first argument is a list of strings, identifying file name patterns used to match against files under the current directory.
  • excludes (defaults to []) A list of patterns to identify files that should be removed from the set specified by the first argument.
  • include_dotfiles (defaults to False) Whether * and ** patterns should capture file or directory names starting with a dot.

Examples

For the purpose of the examples, we call 'regular' a file is that is not a 'dotfile'. A file is a 'dotfile' (relatively to some current directory) if its relative path includes at least one path element starting with a dot. All of the regular .java files in this directory:
glob(['*.java'])
All of the .java files in this directory (now including dotfiles):
glob(['*.java'], include_dotfiles=True)
All of the files under this directory:
glob(['**/'], include_dotfiles=True)
All of the regular files under the directory '.git':
glob(['.git/**/'])
All of the files starting with '.' under a regular (non-dot) directory:
glob(['**/.*'])
All of the regular .java and .aidl files in this directory:
glob(['*.java', '*.aidl'])
All of the regular .java files under this directory:
glob(['**/*.java'])
All of the regular files under this directory that end in Test.java:
glob(['**/*Test.java'])
All of the regular files under this directory that end in Test.java, as well as StringTests.java:
glob(['**/*Test.java', 'StringTests.java'])
All of the regular files under this directory that end in Test.java, except for HaltingProblemTest.java:
glob(['**/*Test.java'], excludes = ['HaltingProblemTest.java'])
All of the regular .java files under this directory, except for those that end in Test.java:
glob(['**/*.java'], excludes = ['**/*Test.java'])