feature: added 'GetParentDir' to files
parent
f8094df331
commit
6019beffe5
|
@ -3,6 +3,7 @@ package files
|
|||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func IsFileExists(fileLocation string) bool {
|
||||
|
@ -12,3 +13,13 @@ func IsFileExists(fileLocation string) bool {
|
|||
|
||||
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
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
import "os"
|
||||
|
||||
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)
|
||||
parentDir := GetParentDir(fileLocation)
|
||||
if parentDir != "" {
|
||||
parentDirCreationErr := os.MkdirAll(parentDir, os.ModeDir)
|
||||
|
||||
if parentDirCreationErr != nil {
|
||||
return parentDirCreationErr
|
||||
|
|
Loading…
Reference in New Issue