Created
May 14, 2019 09:56
-
-
Save leafsummer/c0076de6493215c10cd8d13976537dba to your computer and use it in GitHub Desktop.
[GetCwd]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"path/filepath" | |
"fmt" | |
"os" | |
"strings" | |
"log" | |
) | |
func GetCwd() string { | |
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) | |
if err != nil { | |
log.Fatal(err) | |
} | |
return strings.Replace(dir, "\\", "/", -1) | |
} | |
func main() { | |
var ( | |
cwd string | |
) | |
cwd = GetCwd() | |
fmt.Printf("CWD is %s\n", cwd) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment