filepath.Base() Function in Golang With Examples Last Updated : 10 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.Base() function in Go language used to return the last element of the specified path. Here the trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator. Moreover, this function is defined under the path package. Here, you need to import the "path/filepath" package in order to use these functions. Syntax: func Base(path string) string Here, 'path' is the specified path. Return Value: It return the last element of the specified path. If the path is empty, this function returns ".". If the path consists entirely of separators, this function returns a single separator. Example 1: C // Golang program to illustrate the usage of // filepath.Base() function // Including the main package package main // Importing fmt and path/filepath import ( "fmt" "path/filepath" ) // Calling main func main() { // Calling the Base() function to // get the last element of path fmt.Println(filepath.Base("/home/gfg")) fmt.Println(filepath.Base(".gfg")) fmt.Println(filepath.Base("/gfg")) fmt.Println(filepath.Base(":gfg/GFG")) } Output: gfg .gfg gfg GFG Example 2: C // Golang program to illustrate the usage of // filepath.Base() function // Including the main package package main // Importing fmt and path/filepath import ( "fmt" "path/filepath" ) // Calling main func main() { // Calling the Base() function which // returns "." if the path is empty // and returns a single separator if // the path consists entirely of separators fmt.Println(filepath.Base("")) fmt.Println(filepath.Base(".")) fmt.Println(filepath.Base("/")) fmt.Println(filepath.Base("/.")) fmt.Println(filepath.Base("//")) fmt.Println(filepath.Base(":/")) } Output: . . / . / : Comment More infoAdvertise with us Next Article filepath.Ext() Function in Golang With Examples K Kanchan_Ray Follow Improve Article Tags : Go Language Golang-filepath Similar Reads filepath.Abs() Function in Golang With Examples In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.Abs() function in Go language used to return an absolute representation of the specified path. If the path is not absolute it will be joined with the current working directory to turn 2 min read filepath.Dir() Function in Golang With Examples In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.Dir() function in Go language used to return all the elements of the specified path except the last element. After dropping the final element, Dir calls Clean on the path and trailing 2 min read filepath.Ext() Function in Golang With Examples In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.Ext() function in Go language used to return the file name extension used by the specified path. The extension is the suffix beginning at the final dot in the final element of path; i 2 min read filepath.IsAbs() Function in Golang With Examples In Go language, path package used for paths separated by forwarding slashes, such as the paths in URLs. The filepath.IsAbs() function in Go language used to report whether the path is absolute or not. Moreover, this function is defined under the path package. Here, you need to import the "path/filep 2 min read reflect.Float() Function in Golang with Examples Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Float() Function in Golang is used to get the v's underlying value, as a float64. To access this function, one ne 1 min read bits.Len8() Function in Golang with Examples Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides Len8() function which is used to find the minimum number of bits required to represent a and the result i 2 min read Like