//http://my.oschina.net/itfanr/blog/373983
package main
import (
"fmt"
"path"
"strings"
)
func main() {
fullFilename := "/Users/itfanr/Documents/test.txt"
fmt.Println("fullFilename =", fullFilename)
var filenameWithSuffix string
filenameWithSuffix = path.Base(fullFilename) //获取文件名带后缀
fmt.Println("filenameWithSuffix =", filenameWithSuffix)
var fileSuffix string
fileSuffix = path.Ext(filenameWithSuffix) //获取文件后缀
fmt.Println("fileSuffix =", fileSuffix)
var filenameOnly string
filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)//获取文件名
fmt.Println("filenameOnly =", filenameOnly)
}
有疑问加站长微信联系(非本文作者)