github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/file/fileset.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: fileset - Functions - Configuration Language
     4  description: The fileset function enumerates a set of regular file names given a pattern.
     5  ---
     6  
     7  # `fileset` Function
     8  
     9  `fileset` enumerates a set of regular file names given a path and pattern.
    10  The path is automatically removed from the resulting set of file names and any
    11  result still containing path separators always returns forward slash (`/`) as
    12  the path separator for cross-system compatibility.
    13  
    14  ```hcl
    15  fileset(path, pattern)
    16  ```
    17  
    18  Supported pattern matches:
    19  
    20  - `*` - matches any sequence of non-separator characters
    21  - `**` - matches any sequence of characters, including separator characters
    22  - `?` - matches any single non-separator character
    23  - `{alternative1,...}` - matches a sequence of characters if one of the comma-separated alternatives matches
    24  - `[CLASS]` - matches any single non-separator character inside a class of characters (see below)
    25  - `[^CLASS]` - matches any single non-separator character outside a class of characters (see below)
    26  
    27  Character classes support the following:
    28  
    29  - `[abc]` - matches any single character within the set
    30  - `[a-z]` - matches any single character within the range
    31  
    32  Functions are evaluated by the CLI during configuration parsing rather than job run time,
    33  so this function can only be used with files that are already present on disk on operator host.
    34  
    35  ## Examples
    36  
    37  ```shell-session
    38  > tree pkr-consul
    39  pkr-consul
    40  ├── build-linux.pkr.hcl
    41  └── linux
    42      ├── files
    43      │   ├── hello.txt
    44      │   └── world.txt
    45      └── scripts
    46          ├── script-1-install.sh
    47          └── script-2-setup.sh
    48  
    49  3 directories, 5 files
    50  
    51  > fileset(".", "*")
    52  [
    53    "build-linux.pkr.hcl",
    54  ]
    55  
    56  > echo 'fileset(".", "linux/scripts/*")'
    57  [
    58    "linux/scripts/script-1-install.sh",
    59    "linux/scripts/script-2-setup.sh",
    60  ]
    61  
    62  > echo 'fileset("linux", "files/{hello,world}.txt")'
    63  [
    64    "files/hello.txt",
    65    "files/world.txt",
    66  ]
    67  
    68  > echo 'fileset("./linux/files", "*")'
    69  [
    70    "hello.txt",
    71    "world.txt",
    72  ]
    73  
    74  > echo 'fileset("./linux", "**")'
    75  [
    76    "files/hello.txt",
    77    "files/world.txt",
    78    "scripts/script-1-install.sh",
    79    "scripts/script-2-setup.sh",
    80  ]
    81  ```