From 370efca124c2c7bde958bcda3f8c83604db8a892 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Wed, 1 Feb 2023 16:31:46 +0300 Subject: [PATCH] add osutils --- osutils/files.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 osutils/files.go diff --git a/osutils/files.go b/osutils/files.go new file mode 100644 index 0000000..fd0a28b --- /dev/null +++ b/osutils/files.go @@ -0,0 +1,41 @@ +package osutils + +import ( + "log" + "os" + "path/filepath" +) + +func IsDirectory(path string) (bool, error) { + fileInfo, err := os.Stat(path) + if err != nil { + return false, err + } + + return fileInfo.IsDir(), err +} + +func RecursiceWalk(pathToWalk string) ([]string, error) { + paths := []string{} + err := filepath.Walk(pathToWalk, + func(path string, info os.FileInfo, err error) error { + if err != nil { + println(err) + return err + } + // fmt.Println(path[len(path)-4:]) + libBool, err := IsDirectory(path) + if err != nil { + println("error in checking lib or dir") + } + if !libBool { + // println(path) + paths = append(paths, path) + } + return nil + }) + if err != nil { + log.Println(err) + } + return paths, nil +}