feature: added 'GetParentDir' to files
parent
f8094df331
commit
6019beffe5
|
@ -3,6 +3,7 @@ package files
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsFileExists(fileLocation string) bool {
|
func IsFileExists(fileLocation string) bool {
|
||||||
|
@ -12,3 +13,13 @@ func IsFileExists(fileLocation string) bool {
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetParentDir(fileLocation string) string {
|
||||||
|
fileLocation = strings.ReplaceAll(fileLocation, "\\", "/")
|
||||||
|
indexOfSlash := strings.LastIndex(fileLocation, "/")
|
||||||
|
if indexOfSlash > 0 {
|
||||||
|
return fileLocation[:indexOfSlash]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
package files
|
package files
|
||||||
|
|
||||||
import (
|
import "os"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func MkdirParent(fileLocation string) error {
|
func MkdirParent(fileLocation string) error {
|
||||||
fileLocation = strings.ReplaceAll(fileLocation, "\\", "/")
|
parentDir := GetParentDir(fileLocation)
|
||||||
indexOfSlash := strings.LastIndex(fileLocation, "/")
|
if parentDir != "" {
|
||||||
if indexOfSlash > 0 {
|
parentDirCreationErr := os.MkdirAll(parentDir, os.ModeDir)
|
||||||
parentDirLocation := fileLocation[:indexOfSlash]
|
|
||||||
parentDirCreationErr := os.MkdirAll(parentDirLocation, os.ModeDir)
|
|
||||||
|
|
||||||
if parentDirCreationErr != nil {
|
if parentDirCreationErr != nil {
|
||||||
return parentDirCreationErr
|
return parentDirCreationErr
|
||||||
|
|
Loading…
Reference in New Issue