I would like to use path.Dir() on Unix and Windows with a specific directory on the platform. Please take a look at the code:
package main import ( "fmt" "path" ) func main() { fmt.Println(`path.Dir("a/b/c"): `, path.Dir("a/b/c")) fmt.Println(`path.Dir("c:\foo\bar.exe"): `, path.Dir(`c:\foo\bar.exe`)) }
Displays
path.Dir("a/b/c"): a/b path.Dir("c:\foo\bar.exe"): .
I would like to get a second call to path.Dir() (windows) something like
c:\foo
Is it possible to tell path.Dir() use Windows delimiters for my program running on Windows? Or do I always need to convert the backslash \ to slashes ( / )? What is your preferred strategy here?
source share