You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does 'go version' print?
go version go1.2.1 windows/amd64
What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. This code runs on ubuntu 12.04 http://play.golang.org/p/40d_VGdt3Y
and demonstrates that both path.Split and path.Base correctly returns
the filename at the end of the path.
2. The following code (which can only work on windows because only windows has the TEMP
environment variable). I use %TEMP% because it gives a canonical path on windows OS.
import "path"
import "path/filepath"
import "fmt"
import "os"
func main() {
fmt.Println("%TEMP% = ", os.Getenv("TEMP"))
filename := os.Getenv("TEMP") + string(os.PathSeparator) + "video.mp4"
d, f := path.Split(filename)
base := path.Base(filename)
fmt.Println("f=", f)
fmt.Println("d=", d)
fmt.Println(base)
}
What happened?
The execution produced this output.
1) %TEMP% = C:\Users\gavin\AppData\Local\Temp
2) f=C:\Users\gavin\AppData\Local\Temp\video.mp4
3) d=
4) C:\Users\gavin\AppData\Local\Temp\video.mp4
What should have happened instead?
1) Correct
2) f=video.mp4
3) d=C:\Users\gavin\AppData\Local\Temp
4) video.mp4
Please provide any additional information below.
The text was updated successfully, but these errors were encountered:
The program wrongly mixes use of cross platform os.PathSeparator and cross platform
filepath.Join and non cross platform path package. The later works only with slash
separated paths as documented:
"Package path implements utility routines for manipulating slash-separated paths."[0]
But os.PathSeparator is not a slash on windows.
[0]: http://golang.org/pkg/path/
#WAI
The path package is for slash-separated paths, like URLs.
The path/filepath package is for operating system specific path names.
If you want to use os.PathSeparator--an operating system specific concept--then use
path/filepath, not path.
Use filepath.Base() as it's portable across systems and not the UNIX
specific path.Base():
golang/go#7698
Signed-off-by: Pekka Enberg <penberg@scylladb.com>
by Gavin.Bong:
The text was updated successfully, but these errors were encountered: