Menu Close

Go – How to get the current working directory in go golang

In this tutorial, We are going to learn about how to get the current working directory in go golang.

We can get current working directory using Getwd() function in os package in go golang.

Getwd() function returns a rooted path name corresponding to the current working directory.

If It is possible to reach current working directory via multiple paths (due to symbolic links) then Getwd() function may return any one of them.

Getwd() function prototype:

func Getwd() (dir string, err error) 

Return Type:

  • dir : Current working directory path
  • err : It is type of error.


package main

import (

func main() {
    // Get the current working directory
    curr_wd, err := os.Getwd()

    if err != nil {



    // Print the current working directory



To learn more about golang, You can refer given below link:

Posted in golang, os, packages

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us