dirname equivalent in Go

Issue

I’m studying Go, I don’t know if I missed something, but after searching, I wonder: Does dirname in NodeJS have an equivalent in Go? How to get current directory in Go code, or I have to implement one?

Solution

In Go you can use os.Getwd which returns a rooted path name corresponding to the current directory.

dir, err := os.Getwd()
if err != nil {
    fmt.Errorf("Dir %v does not exists", err)
}

Answered By – Endre Simo

Answer Checked By – Senaida (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.