Skip to content
Node: path.basename(p)github.com/sahilkhaire/gox/path

Basename

Overview

Basename returns the last element (path.basename).

If you are coming from Node.js, the closest pattern is path.basename(p).

Signature

go
func Basename(p string) string

Compare: Node.js · Standard Go · gox

js
path.basename('/foo/bar.txt');
go
name := filepath.Base("/foo/bar.txt")
go
import "github.com/sahilkhaire/gox/path"

name := path.Basename("/foo/bar.txt")

Example

go
import "github.com/sahilkhaire/gox/path"

name := path.Basename("/foo/bar.txt")

Tips

Import github.com/sahilkhaire/gox/path and call Basename directly. See the comparison below for the standard library equivalent.

Standard library alternative

Use the standard library directly:

go
name := filepath.Base("/foo/bar.txt")

Back to path package overview

MIT Licensed · Built for Node.js developers moving to Go