Golang : Get path name to current directory or folder
Problem :
You need to get the path name of the current directory where the executable is residing. How to do that in Golang?
Solution :
Use the os.Getwd()
function.
For example :
package main
import (
"fmt"
"os"
"strings"
)
func main() {
dir, _ := os.Getwd()
fmt.Println(strings.Replace(dir, " ", "\\ ", -1))
}
UPDATE : This is similar to the Linux/Unix command pwd
-- return working directory name.
See also : Golang : get the current working directory of a running program
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+36.4k Golang : Convert(cast) int64 to string
+10.3k Golang : Wait and sync.WaitGroup example
+9.2k Golang : Intercept and compare HTTP response code example
+6.9k Mac/Linux/Windows : Get CPU information from command line
+14k Golang : Get dimension(width and height) of image file
+15.1k Golang : package is not in GOROOT during compilation
+10.6k Golang : ISO8601 Duration Parser example
+16.5k Golang : File path independent of Operating System
+12.3k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+12.8k Golang : Listen and Serve on sub domain example
+22.8k Golang : untar or extract tar ball archive example
+43.4k Golang : Convert []byte to image