In the Go programming language, to get the directory name from a given path – we use the Dir() function of path/filepath package. The Dir() function returns all but the last element of the given path, typically the path's directory. After dropping the final element, Dir() function calls the Clean() function on the path, and trailing slashes are removed. If the given path is empty, it returns ".". If the given path consists entirely of separators, it returns a single separator. The returned path does not end in a separator unless it is the root directory.
Syntax:
Consider the below Golang program demonstrating how to get the directory name from the given path?
Output
need an explanation for this answer? contact us directly to get an explanation for this answer