github.com/jaredpalmer/terraform@v1.1.0-alpha20210908.0.20210911170307-88705c943a03/website/docs/language/functions/dirname.html.md (about)

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