feature: added file name utils

This commit is contained in:
2024-06-21 19:06:09 +03:00
parent e85baa72f6
commit 33bc425e90
3 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package files
import (
"path/filepath"
"slices"
"strings"
"git.tswf.io/incredible-go/incredible-go-core/pkg/collections/array_list"
)
func GetSimpleName(filePath string) string {
return SplitFileName(filePath).GetLast()
}
func GetExtension(filePath string) string {
split := strings.Split(filePath, ".")
return split[len(split)-1]
}
func GetSimpleNameWithoutExtension(filePath string) string {
simpleName := GetSimpleName(filePath)
split := slices.DeleteFunc(strings.Split(simpleName, "."), func(s string) bool {
return s == ""
})
if len(split) == 1 {
return filePath
}
return filepath.Join(split[:len(split)-1]...)
}
func SplitFileName(filePath string) *array_list.ArrayList[string] {
filePath = filepath.ToSlash(filePath)
split := strings.Split(filePath, "/")
return array_list.NewArrayListWithContent[string](split...)
}