Go语言获取路径的文件名、后缀
package main import ( "fmt" "path" "path/filepath" ) func main() { filePath := "D:/DDPS/log/log.txt" paths, fileName := filepath.Split(filePath) fmt.Println(paths, fileName) //获取路径中的目录及文件名 D:/DDPS/log/ log.txt fmt.Println(filepath.Base(filePath)) //获取路径中的文件名log.txt fmt.Println(path.Ext(filePath)) //获取路径中的文件的后缀 .txt }