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
+5.9k Golang : Accurate and reliable decimal calculations
+5.2k Golang : Display list of countries and ISO codes
+14.5k Golang : Delete item from slice based on index/key position
+7.8k Golang : Execute function at intervals or after some delay
+17.6k Golang : Calculate future date with time.Add() function
+41.4k Golang : Upload file from web browser to server
+7.7k Golang : Convert(cast) float to int
+6k Golang : Get dimension(width and height) of image file
+5.3k Golang : Qt progress dialog example
+18.6k Golang : Strip slashes from string example
+3.3k Golang : Get environment variable
+2.2k JavaScript: Add marker function on Google Map