[Golang] Get Filename Without Extension
Use Go standard library to get file name without extension.
- path.Ext method to get filename extension
- strings.TrimSuffix method to remove the extension from the filename.
import (
"path"
"strings"
)
func FilenameWithoutExtension(fn string) string {
return strings.TrimSuffix(fn, path.Ext(fn))
}
Tested on:
- Ubuntu Linux 17.10, Go 1.10.
- The Go Playground