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
+6k Default cipher that OpenSSL used to encrypt a PEM file
+6.5k Golang : Dealing with postal or zip code example
+9.8k Golang : Bubble sort example
+9.2k Golang : Find and replace data in all files recursively
+6.5k Golang : Calculate how many weeks left to go in a given year
+9.7k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+13.7k Golang : Execute function at intervals or after some delay
+4.6k Javascript : How to loop over and parse JSON data?
+11.5k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+14.5k Golang : Delete certain files in a directory
+19.3k Nginx + FastCGI + Go Setup.
+3.7k Javascript : How to show different content with noscript?