Share & grow the world's code base!

Delve into a community where programmers unite to discover code snippets, exchange skills, and enhance their programming proficiency. With abundant resources and a supportive community, you'll find everything essential for your growth and success.

1 snippets
  • Filename without extension in Go

    package main
    
    import (
        "fmt"
        "path/filepath"
        "strings"
    )
    
    func main() {
        filePath := "/tmp/file.ext"
    
        // get file name with extension
        fileName := filepath.Base(filePath)
    
        // get file extension
        fileExt := filepath.Ext(filePath)
    
        // truncate file name extension
        fileNameWithoutExt := strings.TrimSuffix(fileName, fileExt)
    
        fmt.Println("File name without extension: " + fileNameWithoutExt)
    }
    
    // $ go run main.go
    // File name without extension: file

    Here is an example of how to get filename without extension in go.