github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/dirname.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "dirname - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-file-dirname"
     5  description: |-
     6    The dirname function removes the last portion from a filesystem path.
     7  ---
     8  
     9  # `dirname` Function
    10  
    11  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    12  earlier, see
    13  [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
    14  
    15  `dirname` takes a string containing a filesystem path and removes the last
    16  portion from it.
    17  
    18  This function works only with the path string and does not access the
    19  filesystem itself. It is therefore unable to take into account filesystem
    20  features such as symlinks.
    21  
    22  If the path is empty then the result is `"."`, representing the current
    23  working directory.
    24  
    25  The behavior of this function depends on the host platform. On Windows systems,
    26  it uses backslash `\` as the path segment separator. On Unix systems, the slash
    27  `/` is used. The result of this function is normalized, so on a Windows system
    28  any slashes in the given path will be replaced by backslashes before returning.
    29  
    30  Referring directly to filesystem paths in resource arguments may cause
    31  spurious diffs if the same configuration is applied from multiple systems or on
    32  different host operating systems. We recommend using filesystem paths only
    33  for transient values, such as the argument to [`file`](./file.html) (where
    34  only the contents are then stored) or in `connection` and `provisioner` blocks.
    35  
    36  ## Examples
    37  
    38  ```
    39  > dirname("foo/bar/baz.txt")
    40  foo/bar
    41  ```
    42  
    43  ## Related Functions
    44  
    45  * [`basename`](./basename.html) returns _only_ the last portion of a filesystem
    46    path, discarding the portion that would be returned by `dirname`.