Add method ListDir

This commit is contained in:
cyber-dream 2023-02-04 14:13:00 +03:00
parent 618b0b1639
commit 6f1cc3cc7c

View File

@ -1,9 +1,13 @@
package osutils package osutils
import ( import (
"io/fs"
"io/ioutil"
"log" "log"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings"
) )
func IsDirectory(path string) (bool, error) { func IsDirectory(path string) (bool, error) {
@ -39,3 +43,18 @@ func RecursiceWalk(pathToWalk string) ([]string, error) {
} }
return paths, nil 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
}