golang check file extension
To check the file extension in Go (Golang), you can follow these steps:
- Import the necessary packages:
import (
"fmt"
"path/filepath"
)
- Define a function to check the file extension:
func checkFileExtension(filename string) {
ext := filepath.Ext(filename)
fmt.Println("File extension:", ext)
}
- Call the function and pass the file name as an argument:
func main() {
filename := "example.txt"
checkFileExtension(filename)
}
Let me know if you have any further questions.