Adds function to find directory of file on working path
This commit is contained in:
parent
a23f6f21b9
commit
9201c7f360
@ -15,6 +15,7 @@
|
|||||||
package helpers
|
package helpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -52,3 +53,17 @@ func Exists(path string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindFileDir returns the path of the
|
||||||
|
func FindFileDir(file string) (string, error) {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
for path := wd; path != "."; path = filepath.Dir(path) {
|
||||||
|
if Exists(filepath.Join(path, file)) {
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", errors.New("directory not found")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user