filepath.Match failing to match (Windows r60.3)

238 views
Skip to first unread message

Christopher Redden

unread,
Feb 8, 2012, 6:28:47 PM2/8/12
to golang-nuts
The code below is failing to match on my Windows build of r60.3. It
works on the Playground and someone else has tested it for me on OS X.

Could someone else confirm it as an issue on Windows?

On a side note - any way to debug Go packages?

http://pastebin.com/EgXDrLEt

package main

import (
"fmt"
"path/filepath"
)

func main() {
matched, _ := filepath.Match("*.layout", "C:\\Users\\UserName\
\TabPage1.layout")
if matched == true {
fmt.Println("Matched")
}
}

Rob 'Commander' Pike

unread,
Feb 8, 2012, 7:41:48 PM2/8/12
to Christopher Redden, golang-nuts

Whether that's a match depends on your operating system.

-rob

peterGo

unread,
Feb 9, 2012, 2:16:07 AM2/9/12
to golang-nuts
Christopher,

The bug is in your program. To debug your program, carefully read the
documentation for the path/filepath.Match function. Especially, "'*'
matches any sequence of non-Separator characters" and "Match requires
pattern to match all of name, not just a substring."
http://golang.org/pkg/path/filepath/#Match

Here's a corrected version of your program.

package main

import (
"fmt"
"path/filepath"
)

func main() {
name := filepath.Base("C:\\Users\\UserName\\TabPage1.layout")
matched, _ := filepath.Match("*.layout", name)
if matched == true {
fmt.Println("Matched")
}
}

Peter

On Feb 8, 6:28 pm, Christopher Redden <christopher.red...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages