Go version

go1.21.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/go/pkg/mod'
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE='github.com/kodemsec'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2950803868=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I'm trying to get the base name of an absolute windows file path: C:\Program Files\Java\jdk-24\bin\server\jvm.dll

My program is an ELF executable running on linux.

Here's a code that reproduces the issue: https://go.dev/play/p/-LaynyUnMoi

What did you see happen?

I got the absolute path: C:\Program Files\Java\jdk-24\bin\server\jvm.dll

What did you expect to see?

I expected to get the base name: jvm.dll

This issue happened only when this program was built and ran on linux or darwin. When I build this program on windows, it works as expected.

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: seankhliao

path/filepath will only work for the os it's built on, not generically across OSes. if you need to process windows paths on Linux then you need something else