go获取文件名和后缀
go获取文件名和后缀
fullFilename := "D:/software/Typora/bin/typora.exe" fmt.Println("fullFilename =", fullFilename) //获取文件名带后缀 filenameWithSuffix := path.Base(fullFilename) fmt.Println("filenameWithSuffix =", filenameWithSuffix) //获取文件后缀 fileSuffix := path.Ext(filenameWithSuffix) fmt.Println("fileSuffix =", fileSuffix) //获取文件名 filenameOnly := strings.TrimSuffix(filenameWithSuffix, fileSuffix) fmt.Println("filenameOnly =", filenameOnly) ————————————————
输出结果如下
fullFilename = D:/software/Typora/bin/typora.exe filenameWithSuffix = typora.exe fileSuffix = .exe filenameOnly = typora