2022-08-03 14:55:48 +00:00
|
|
|
package owl
|
2022-07-20 17:33:22 +00:00
|
|
|
|
2022-07-23 15:19:47 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
2022-07-20 17:33:22 +00:00
|
|
|
|
|
|
|
func dirExists(path string) bool {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
return err == nil
|
|
|
|
}
|
2022-07-20 17:35:31 +00:00
|
|
|
|
2022-07-23 15:19:47 +00:00
|
|
|
// lists all files/dirs in a directory, not recursive
|
2022-07-20 17:35:31 +00:00
|
|
|
func listDir(path string) []string {
|
|
|
|
dir, _ := os.Open(path)
|
|
|
|
defer dir.Close()
|
|
|
|
files, _ := dir.Readdirnames(-1)
|
|
|
|
return files
|
|
|
|
}
|
2022-07-23 15:19:47 +00:00
|
|
|
|
2022-08-03 16:03:10 +00:00
|
|
|
func fileExists(path string) bool {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
return err == nil
|
|
|
|
}
|
|
|
|
|
2022-07-23 15:19:47 +00:00
|
|
|
// recursive list of all files in a directory
|
|
|
|
func walkDir(path string) []string {
|
|
|
|
files := make([]string, 0)
|
|
|
|
filepath.Walk(path, func(subPath string, info os.FileInfo, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if info.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
files = append(files, subPath[len(path)+1:])
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return files
|
|
|
|
}
|