add 'DirsWithPrefix' function
This commit is contained in:
parent
18f9120c8c
commit
16cb002a8d
16
goutil.go
16
goutil.go
|
@ -85,6 +85,22 @@ func PathExists(path string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DirsWithPrefix(path string, prefix string) ([]string, error) {
|
||||||
|
dirs := []string{}
|
||||||
|
files, err := ioutil.ReadDir(path)
|
||||||
|
if err != nil {
|
||||||
|
return dirs, err
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if file.IsDir() {
|
||||||
|
if name := file.Name(); strings.HasPrefix(name, prefix) {
|
||||||
|
dirs = append(dirs, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dirs, nil
|
||||||
|
}
|
||||||
|
|
||||||
func AskFor(question string) (string, error) {
|
func AskFor(question string) (string, error) {
|
||||||
fmt.Print(question + ": ")
|
fmt.Print(question + ": ")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user