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
+7.8k Javascript : How to check a browser's Do Not Track status?
+7.5k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+24k Golang : Upload to S3 with official aws-sdk-go package
+29.7k Golang : Get and Set User-Agent examples
+8k Golang : Variadic function arguments sanity check example
+7.3k Linux : How to fix Brother HL-1110 printing blank page problem
+9.1k Golang : does not implement flag.Value (missing Set method)
+8.1k Golang : Randomize letters from a string example
+10.1k Golang : How to profile or log time spend on execution?
+6.8k Golang : Decode XML data from RSS feed
+11.2k Golang : Intercept and process UNIX signals example
+12.6k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard