pwd Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/pwd/ Thu, 16 Jan 2020 04:57:08 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 pwd Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/pwd/ 32 32 159787465 Get Current Working Directory in Go (Golang) https://vikasboss.github.io/current-working-directory-golang/ https://vikasboss.github.io/current-working-directory-golang/#respond Thu, 16 Jan 2020 04:56:21 +0000 https://vikasboss.github.io/?p=1171 os.Getwd() is used to get the current working directory. Output will similar to pwd command on linux Output: Current Working Direcoty: <will be current working directory on the machine>

The post Get Current Working Directory in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
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>

The post Get Current Working Directory in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/current-working-directory-golang/feed/ 0 1171