Welcome To Golang By Example

Menu
  • Home
  • Blog
Menu

Get Current Working Directory in Go (Golang)

Posted on January 16, 2023January 16, 2023 by admin

os.Getwd() is used to get the current working directory. Output will similar to pwd command on linux

package main
import (
"fmt"
"log"
"os"
)
func main() {
currentWorkingDirectory, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Current Wroking Direcoty: %s", currentWorkingDirectory)
}

Output:

Current Working Direcoty: <will be current working directory on the machine>

  • directory
  • go
  • golang
  • pwd
  • Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2023 Welcome To Golang By Example | Design: Web XP