Buck: glob()

glob()

The glob() function specifies a set of files using patterns.

A pattern is structured as a relative path with no repeated or trailing path separators, such as the forward slash (/).

Patterns may contain shell-like wildcards, such as * , ? , or [charset].

Additionally, the path element, ** , matches any subpath. For instance

foo/**/bar

is equivalent to

["foo/bar", "foo/*/bar", "foo/*/*/bar", ...]

The patterns that specify the set of files to include—as well as the patterns that specify the files to exclude (see the exclude parameter below)—must both be statically defined; you cannot generate these patterns dynamically at build time.

Arguments

  • The first parameter is unnamed and is a list of patterns that match files under the current directory.
  • exclude (defaults to []) A list of patterns that identify files that should be removed from the set specified by the first parameter. You cannot specify both the exclude parameter and the excludes parameter because they serve the same purpose.
  • include_dotfiles (defaults to False) Specifies whether * and ** patterns should capture file and directory names that start with a dot (.). By default, this parameter is false, which indicates that files that start with a dot are automatically excluded.
  • excludes (defaults to []) DEPRECATED
    This parameter is deprecated; use the exclude parameter instead of excludes.
    A list of patterns that identify files that should be removed from the set specified by the first argument.

Examples

For the purposes of these examples, a regular file is one that is not a dotfile; a file is a dotfile if its path—relative to the current directory—includes at least one path element that starts with a dot.

All the regular .java files in the current directory:

glob(['*.java'])

All the .java files in the current directory—including dotfiles:

glob(['*.java'], include_dotfiles=True)

All the files under the current directory:

glob(['**/'], include_dotfiles=True)

All the regular files under the directory .git:

glob(['.git/**/'])

All the files starting with '.' under regular (non-dot) directories:

glob(['**/.*'])

All the regular .java and .aidl files in the current directory:

glob(['*.java', '*.aidl'])

All the regular .java files under current directory:

glob(['**/*.java'])

All of regular files under the current directory that end in Test.java:

glob(['**/*Test.java'])

All the regular files under the current directory that end in Test.java, as well as StringTests.java:

glob(['**/*Test.java', 'StringTests.java'])

All the regular files under the current directory that end in Test.java, except for HaltingProblemTest.java:

glob(['**/*Test.java'], exclude = ['HaltingProblemTest.java'])

All the regular .java files under the current directory, except for those that end in Test.java:

glob(['**/*.java'], exclude = ['**/*Test.java'])