Standard library / path/filepath

path/filepath.SplitList()

Splits an OS path-list string using the path-list separator; unlike strings.Split, empty input yields an empty slice. Example uses a disposable temporary workspace. Expected stdout: '[a b]\n'.

Formal Syntax & Structure

go syntaxgo
func SplitList(path string) []string

Parameters & Attributes

NameTypeDescription
pathstringPathname interpreted according to this package.

Return Value

[]string

Splits an OS path-list string using the path-list separator; unlike strings.Split, empty input yields an empty slice.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "path/filepath")
func check(e error) {  if e != nil {    panic(e)  }}func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() {  defer workspace()()  fmt.Println(filepath.SplitList("a" + string(filepath.ListSeparator) + "b"))}
Go Reference