| 1 |
--- |
| 2 |
title: path.Split |
| 3 |
description: Replaces path separators with slashes (`/`) and splits the resulting path immediately following the final slash, separating it into a directory and file name component. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: paths.DirFile |
| 10 |
signatures: [path.Split PATH] |
| 11 |
aliases: [/functions/path.split] |
| 12 |
--- |
| 13 |
|
| 14 |
If there is no slash in the given path, `path.Split` returns an empty directory, and file set to path. The returned values have the property that path = dir+file. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ $dirFile := path.Split "a/news.html" }} |
| 18 |
{{ $dirFile.Dir }} → a/ |
| 19 |
{{ $dirFile.File }} → news.html |
| 20 |
|
| 21 |
{{ $dirFile := path.Split "news.html" }} |
| 22 |
{{ $dirFile.Dir }} → "" (empty string) |
| 23 |
{{ $dirFile.File }} → news.html |
| 24 |
|
| 25 |
{{ $dirFile := path.Split "a/b/c" }} |
| 26 |
{{ $dirFile.Dir }} → a/b/ |
| 27 |
{{ $dirFile.File }} → c |
| 28 |
``` |