Q:

How to get the file name extension used by path in Golang?

0

In the Go programming language, to get the file name extension used by the given path – we use the Ext() function of path/filepath package. The Ext() function returns the file name extension used by the given path. The extension is the suffix beginning at the final dot in the final element of the given path; it is empty if there is no dot.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Syntax:

func Ext(path string) string

Consider the below Golang program demonstrating get the file name extension used by the given path?

package main

import (
	"fmt"
	"path/filepath"
)

func main() {
	ext1 := filepath.Ext("/tmp/test.go")
	fmt.Println("ext1:", ext1)

	ext2 := filepath.Ext("./picture1.jpg")
	fmt.Println("ext2:", ext2)
}

Output

ext1: .go
ext2: .jpg

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now