path.Dir.md (783B)
1 ---
2 title: path.Dir
3 description: Dir returns all but the last element of a path.
4 date: 2018-11-28
5 publishdate: 2018-11-28
6 lastmod: 2018-11-28
7 categories: [functions]
8 menu:
9 docs:
10 parent: "functions"
11 keywords: [path, dir]
12 signature: ["path.Dir PATH"]
13 workson: []
14 hugoversion: "0.40"
15 relatedfuncs: [path.Base, path.BaseName, path.Clean, path.Ext, path.Join, path.Split]
16 deprecated: false
17 ---
18
19 `path.Dir` returns all but the last element of `PATH`, typically `PATH`'s directory.
20
21 The returned path will never end in a slash.
22 If `PATH` is empty, `.` is returned.
23
24 **Note:** On Windows, `PATH` is converted to slash (`/`) separators.
25
26 ```
27 {{ path.Dir "a/news.html" }} → "a"
28 {{ path.Dir "news.html" }} → "."
29 {{ path.Dir "a/b/c" }} → "a/b"
30 {{ path.Dir "/x/y/z" }} → "/x/y"
31 ```