123456789101112131415161718192021222324 |
- package sys
- import (
- "os"
- "os/exec"
- "path/filepath"
- "strings"
- )
- // GetCurrentDir get current process directory
- func GetCurrentDir() string {
- file, _ := exec.LookPath(os.Args[0])
- path, _ := filepath.Abs(file)
- idx := strings.LastIndex(path, string(os.PathSeparator))
- return path[:idx]
- }
- // FileReadWrite open file with read/write/append, created if not exists
- func FileReadWrite(path string) (fp *os.File, err error) {
- fp, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
- return
- }
|