diff --git a/pkg/io/files/file_exists_checker.go b/pkg/io/files/file_exists_checker.go index 1629370..be92e3d 100644 --- a/pkg/io/files/file_exists_checker.go +++ b/pkg/io/files/file_exists_checker.go @@ -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 "" +} diff --git a/pkg/io/files/parent_file_creator.go b/pkg/io/files/parent_file_creator.go index 835863e..73a86c6 100644 --- a/pkg/io/files/parent_file_creator.go +++ b/pkg/io/files/parent_file_creator.go @@ -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