Last active
April 16, 2016 15:22
-
-
Save mantyr/afad4e33a30b70f93347694a1adb9240 to your computer and use it in GitHub Desktop.
Get directory of binary program
This file contains 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 ( | |
"fmt" | |
"log" | |
"os" | |
"path/filepath" | |
) | |
func main() { | |
dir, err := filepath.Abs(filepath.Dir(os.Args[0])) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(dir) | |
} |
This file contains 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 | |
// moved to github.com/mantyr/runner.GetDirBin() | |
func GetDirBin() (dir string, err error) { | |
dir, err = filepath.Abs(filepath.Dir(os.Args[0])) | |
if strings.Index(dir, "/tmp/go-build") == 0 || err != nil{ | |
dir, err = os.Getwd() | |
} | |
return | |
} |
This file contains 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
Stack Overflow question: | |
Golang: How to Get the Directory of the Currently running File? | |
http://stackoverflow.com/questions/18537257/golang-how-to-get-the-directory-of-the-currently-running-file | |
Toster question: | |
Как в Go получить абсолютный путь запущенной программы? | |
https://toster.ru/q/149611 |
This file contains 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 ( | |
"github.com/kardianos/osext" | |
"fmt" | |
"log" | |
) | |
func main() { | |
folderPath, err := osext.ExecutableFolder() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(folderPath) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment