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
+8.8k Golang : Combine slices but preserve order example
+21.3k Golang : For loop continue,break and range
+16.5k Golang : Find out mime type from bytes in buffer
+25.9k Golang : missing Mercurial command
+31.8k Golang : bufio.NewReader.ReadLine to read file line by line
+9.1k Golang : GMail API create and send draft with simple upload attachment example
+20k Golang : Archive directory with tar and gzip
+9.9k Golang : Load ASN1 encoded DSA public key PEM file example
+5k Golang : A program that contain another program and executes it during run-time
+9.2k Golang : Get SPF and DMARC from email headers to fight spam
+13.6k Golang : Increment string example
+32.3k Golang : Convert an image file to []byte