github.com/omnigres/cli@v0.1.4/internal/fileutils/fileutils.go (about) 1 package fileutils 2 3 import ( 4 "os" 5 "path/filepath" 6 ) 7 8 func CreateIfNotExists(path string, isDirectory bool) (err error) { 9 if isDirectory { 10 err = os.MkdirAll(path, 0o755) 11 return 12 } else { 13 err = os.MkdirAll(filepath.Dir(path), 0o755) 14 } 15 if err != nil { 16 return 17 } 18 19 file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) 20 if err != nil { 21 return 22 } 23 defer file.Close() 24 return 25 }