path.BaseName.md (652B)
1 --- 2 title: path.BaseName 3 description: BaseName returns the last element of a path, removing the extension if present. 4 date: 2022-06-04 5 categories: [functions] 6 menu: 7 docs: 8 parent: "functions" 9 keywords: [path, base] 10 signature: ["path.BaseName PATH"] 11 relatedfuncs: [path.Base, path.Clean, path.Dir, path.Ext, path.Join, path.Split] 12 deprecated: false 13 --- 14 15 If `PATH` is empty, `.` is returned. 16 17 **Note:** On Windows, `PATH` is converted to slash (`/`) separators. 18 19 ```go-html-template 20 {{ path.BaseName "a/news.html" }} → "news" 21 {{ path.BaseName "news.html" }} → "news" 22 {{ path.BaseName "a/b/c" }} → "c" 23 {{ path.BaseName "/x/y/z/" }} → "z" 24 ```