Tag:File prefix

  • Go language obtains the name, prefix and suffix of the file


    Example code: package main import ( “fmt” “path” ) func main() { filename := “device/sdk/CMakeLists.txt” filenameall := path.Base(filename) filesuffix := path.Ext(filename) fileprefix := filenameall[0:len(filenameall) – len(filesuffix)] //fileprefix, err := strings.TrimSuffix(filenameall, filesuffix) fmt.Println(“file name:”, filenameall) fmt.Println(“file prefix:”, fileprefix) fmt.Println(“file suffix:”, filesuffix) } Execution results: file name: CMakeLists.txt file prefix: CMakeLists file suffix: .txt path.Base(filename) Gets the […]