feature: added FS utils
parent
e89429a93c
commit
72cc77ef77
|
@ -0,0 +1,15 @@
|
|||
package files
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func OpenFileForWriting(fileLocation string) (*os.File, error) {
|
||||
err := MkdirParent(fileLocation)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return os.Create(fileLocation)
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package files
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func MkdirParent(fileLocation string) error {
|
||||
fileLocation = strings.ReplaceAll(fileLocation, "\\", "/")
|
||||
indexOfSlash := strings.LastIndex(fileLocation, "/")
|
||||
if indexOfSlash > 0 {
|
||||
parentDirLocation := fileLocation[:indexOfSlash]
|
||||
parentDirCreationErr := os.MkdirAll(parentDirLocation, os.ModeDir)
|
||||
|
||||
if parentDirCreationErr != nil {
|
||||
return parentDirCreationErr
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue