2021-10-09 14:36:57 -04:00
|
|
|
---
|
|
|
|
title: path.Clean
|
|
|
|
description: Replaces path separators with slashes (`/`) and removes extraneous separators.
|
|
|
|
date: 2021-10-08
|
|
|
|
# publishdate: 2018-11-28
|
|
|
|
# lastmod: 2018-11-28
|
|
|
|
categories: [functions]
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "functions"
|
2022-06-04 16:40:32 -04:00
|
|
|
keywords: [path, clean]
|
2021-10-09 14:36:57 -04:00
|
|
|
signature: ["path.Clean PATH"]
|
2022-06-04 16:40:32 -04:00
|
|
|
relatedfuncs: [path.Base, path.BaseName, path.Dir, path.Ext, path.Join, path.Split]
|
2021-10-09 14:36:57 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
`path.Clean` replaces path separators with slashes (`/`) and removes extraneous separators, including trailing separators.
|
|
|
|
|
|
|
|
```
|
|
|
|
{{ path.Clean "foo//bar" }} → "foo/bar"
|
|
|
|
{{ path.Clean "/foo/bar/" }} → "/foo/bar"
|
|
|
|
```
|
|
|
|
|
|
|
|
On a Windows system, if `.File.Path` is `foo\bar.md`, then:
|
|
|
|
|
|
|
|
```
|
|
|
|
{{ path.Clean .File.Path }} → "foo/bar.md"
|
|
|
|
```
|