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
+10k Golang : Detect number of faces or vehicles in a photo
+6.9k Golang : Transform lisp or spinal case to Pascal case example
+6.6k Golang : Muxing with Martini example
+9.1k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+25.7k Mac/Linux and Golang : Fix bind: address already in use error
+8.6k Golang : Accept any number of function arguments with three dots(...)
+8.6k Golang : HTTP Routing with Goji example
+14.3k Golang : How to get URL port?
+16.8k Golang : How to save log messages to file?
+11.7k Golang : Sort and reverse sort a slice of runes
+8.4k Golang : How to join strings?
+25k Golang : Get current file path of a file or executable