Files
mp-qvyun/backend/pkg/path/fs.go
2024-12-05 11:32:00 +08:00

38 lines
615 B
Go

package path
import (
"os"
"github.com/pkg/errors"
)
func GetSubDirs(root string) ([]string, error) {
fd, err := os.Open(root)
if err != nil {
return nil, errors.Wrapf(err, "open root directory: %s", root)
}
defer fd.Close()
entries, err := fd.Readdir(-1)
if err != nil {
return nil, errors.Wrapf(err, "read root directory: %s", root)
}
var paths []string
for _, entry := range entries {
if entry.IsDir() {
paths = append(paths, entry.Name())
}
}
return paths, nil
}
func DirExists(path string) bool {
st, err := os.Stat(path)
if err != nil {
return false
}
return st.IsDir()
}