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
+6.8k Golang : How to solve "too many .rsrc sections" error?
+8.2k Golang : Count leading or ending zeros(any item of interest) example
+12.9k Swift : Convert (cast) Int to String ?
+8.5k Golang : Set or add headers for many or different handlers
+6.8k Fix sudo yum hang problem with no output or error messages
+9k Golang : Simple histogram example
+10k Golang : Print how to use flag for your application example
+6.8k Golang : How to setup a disk space used monitoring service with Telegram bot
+7.4k Golang : Shuffle strings array
+19.2k Golang : Fix cannot download, $GOPATH not set error
+8.1k Golang : Add build version and other information in executables
+25.6k Golang : How to write CSV data to file