25 lines
500 B
Go
25 lines
500 B
Go
package apputil
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// EnsureDir checks a file could be written to a path, creates the directories
|
|
// as needed
|
|
func EnsureDir(fileName string) {
|
|
dirName := filepath.Dir(fileName)
|
|
if _, serr := os.Stat(dirName); serr != nil {
|
|
merr := os.MkdirAll(dirName, os.ModePerm)
|
|
if merr != nil {
|
|
panic(merr)
|
|
}
|
|
}
|
|
}
|
|
|
|
// FileExists reports whether the named file or directory exists.
|
|
func FileExists(filePath string) bool {
|
|
_, e := os.Stat(filePath)
|
|
return e == nil
|
|
}
|