Answers for "golang get current directory"

Go
4

goland how to print out your current path

package main
// More info on Getwd()
// https://golang.org/src/os/getwd.go

import(
  "os" 
  "fmt"
  "log"
)

func main() {
	dir, err := os.Getwd()
	if err != nil || dir == "" {
		log.Fatalf("Error: %v", err.Error())
	}
	log.Printf("Current Working Dir: %v", dir)
}
Posted by: Guest on May-06-2020
1

golang get working directory

path, err := os.Getwd()
if err != nil {
    log.Println(err)
}
fmt.Println(path)  // for example /home/user
Posted by: Guest on April-13-2021
0

golang get working directory

path, err := os.Executable()
if err != nil {
    log.Println(err)
}
fmt.Println(path) // for example /tmp/go-build872132473/b001/exe/main
Posted by: Guest on April-13-2021

Code answers related to "golang get current directory"

Browse Popular Code Answers by Language