github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/hcl2/functions/file/fileset.mdx (about)

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