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
+10.7k Golang : ISO8601 Duration Parser example
+21.6k Golang : How to read float value from standard input ?
+18.9k Golang : Delete duplicate items from a slice/array
+4.5k Golang : Valued expressions and functions example
+13.5k Golang : Generate Code128 barcode
+17.1k Golang : Get number of CPU cores
+8k Swift : Convert (cast) String to Float
+6.6k PHP : Shuffle to display different content or advertisement
+6.5k Golang : Break string into a slice of characters example
+6.1k Golang : Missing Subversion command
+6.6k Unix/Linux : How to get own IP address ?