Standard library / path/filepath
path/filepath.Match()
Matches an entire OS pathname against a shell-style pattern. Separator and escape rules vary by OS; syntax errors are returned. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Match(pattern, name string) (matched bool, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pattern | string | Shell-style matching pattern. |
| name | string | Name or pathname of the target. |
Return Value
(matched bool, err error)
Matches an entire OS pathname against a shell-style pattern.
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()(); m, e := filepath.Match("*.txt", "go.txt"); check(e); fmt.Println(m) }