From 6f1cc3cc7c6bfb28cdd58b359629a8d4b2060dad Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sat, 4 Feb 2023 14:13:00 +0300 Subject: [PATCH] Add method ListDir --- osutils/files.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/osutils/files.go b/osutils/files.go index fd0a28b..d3e0af7 100644 --- a/osutils/files.go +++ b/osutils/files.go @@ -1,9 +1,13 @@ package osutils import ( + "io/fs" + "io/ioutil" "log" "os" + "path" "path/filepath" + "strings" ) func IsDirectory(path string) (bool, error) { @@ -39,3 +43,18 @@ func RecursiceWalk(pathToWalk string) ([]string, error) { } return paths, nil } + +func ListDir(path string) ([]fs.FileInfo, error) { + files, err := ioutil.ReadDir(path) + if err != nil { + log.Fatal(err) + return []fs.FileInfo{}, err + } + return files, nil +} + +func GetParentDir(filePath string) (string, error) { + cuttedPath := strings.Split(filePath, "/") + cuttedPath = cuttedPath[:len(cuttedPath)-1] + return path.Join(cuttedPath...), nil +}