github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/file/dirname.mdx (about) 1 --- 2 layout: docs 3 page_title: dirname - Functions - Configuration Language 4 description: The dirname function removes the last portion from a filesystem path. 5 --- 6 7 # `dirname` Function 8 9 `dirname` takes a string containing a filesystem path and removes the last 10 portion from it. 11 12 This function works only with the path string and does not access the 13 filesystem itself. It is therefore unable to take into account filesystem 14 features such as symlinks. 15 16 If the path is empty then the result is `"."`, representing the job file directory. 17 18 The behavior of this function depends on the host platform. On Windows systems, 19 it uses backslash `\` as the path segment separator. On Unix systems, the slash 20 `/` is used. The result of this function is normalized, so on a Windows system 21 any slashes in the given path will be replaced by backslashes before returning. 22 23 Referring directly to filesystem paths in job arguments may cause 24 spurious diffs if the same configuration is applied from multiple systems or on 25 different host operating systems. We recommend using filesystem paths only 26 for transient values, such as the argument to [`file`](/docs/job-specification/hcl2/functions/file/file) (where 27 only the contents are then stored). 28 29 ## Examples 30 31 ```shell-session 32 > dirname("foo/bar/baz.txt") 33 foo/bar 34 ``` 35 36 ## Related Functions 37 38 - [`basename`](/docs/job-specification/hcl2/functions/file/basename) returns _only_ the last portion of a filesystem 39 path, discarding the portion that would be returned by `dirname`.