Re: [go-nuts] How to properly get basename under DOS?
Like this? -- https://play.golang.org/p/jhK-vmmmdH package main import ( "fmt" "path/filepath" ) func main() { fmt.Println(filepath.Base("/a/b.c")) fmt.Println(filepath.Base(`C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe`)) } The output is still exactly the same as before. On Tuesday, June 14, 2016 at 1:01:18 PM UTC-4, Jan Mercl wrote: > > Package path is for *nix paths only. import "path/filepath" instead. > > On Tue, Jun 14, 2016, 18:55 Tong Sun> wrote: > >> I thought to get basename, we should use the official *path.Base* -- >> https://golang.org/pkg/path/#Base >> >> However, I just found out that it is *not working under DOS* -- >> https://play.golang.org/p/kfr0N50JWc >> >> package main >> >> >> import ( >> "fmt" >> "path" >> ) >> >> >> func main() { >> fmt.Println(path.Base("/a/b.c")) >> fmt.Println(path.Base(`C:\Program Files\Microsoft Visual Studio >> 9\Common7\IDE\devenv.exe`)) >> } >> >> >> The output is: >> >> b.c >> C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe >> >> >> What's your solution for this, that is working for both Linux and >> Windows? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > -- > > -j > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
RE: [go-nuts] How to properly get basename under DOS?
> Package path is for *nix paths only. import "path/filepath" instead. When should path be used? Or should it be deprecated in favor of path/filepath? John John Souvestre - New Orleans LA From: golang-nuts@googlegroups.com [mailto:golang-nuts@googlegroups.com] On Behalf Of Jan Mercl Sent: 2016 June 14, Tue 12:01 To: Tong Sun; golang-nuts Subject: Re: [go-nuts] How to properly get basename under DOS? Package path is for *nix paths only. import "path/filepath" instead. On Tue, Jun 14, 2016, 18:55 Tong Sun <suntong...@gmail.com> wrote: I thought to get basename, we should use the official path.Base -- https://golang.org/pkg/path/#Base However, I just found out that it is not working under DOS -- https://play.golang.org/p/kfr0N50JWc package main import ( "fmt" "path" ) func main() { fmt.Println(path.Base("/a/b.c")) fmt.Println(path.Base(`C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe`)) } The output is: b.c C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe What's your solution for this, that is working for both Linux and Windows? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to properly get basename under DOS?
On Tue, Jun 14, 2016 at 10:00 AM, Jan Mercl <0xj...@gmail.com> wrote: > Package path is for *nix paths only. import "path/filepath" instead. I agree that path/filepath is what you want, but I would say it slightly differently. path is for what you find inside URLs, path/filepath is for paths in the file system on both Unix and Windows. Ian > On Tue, Jun 14, 2016, 18:55 Tong Sunwrote: >> >> I thought to get basename, we should use the official path.Base -- >> https://golang.org/pkg/path/#Base >> >> However, I just found out that it is not working under DOS -- >> https://play.golang.org/p/kfr0N50JWc >> >> package main >> >> >> import ( >> "fmt" >> "path" >> ) >> >> >> func main() { >> fmt.Println(path.Base("/a/b.c")) >> fmt.Println(path.Base(`C:\Program Files\Microsoft Visual Studio >> 9\Common7\IDE\devenv.exe`)) >> } >> >> >> The output is: >> >> b.c >> C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe >> >> >> What's your solution for this, that is working for both Linux and Windows? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. > > -- > > -j > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How to properly get basename under DOS?
Package path is for *nix paths only. import "path/filepath" instead. On Tue, Jun 14, 2016, 18:55 Tong Sunwrote: > I thought to get basename, we should use the official *path.Base* -- > https://golang.org/pkg/path/#Base > > However, I just found out that it is *not working under DOS* -- > https://play.golang.org/p/kfr0N50JWc > > package main > > > import ( > "fmt" > "path" > ) > > > func main() { > fmt.Println(path.Base("/a/b.c")) > fmt.Println(path.Base(`C:\Program Files\Microsoft Visual Studio > 9\Common7\IDE\devenv.exe`)) > } > > > The output is: > > b.c > C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe > > > What's your solution for this, that is working for both Linux and Windows? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.