30 lines
497 B
Go
30 lines
497 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
|
|
}
|