add 'DirsWithPrefix' function

This commit is contained in:
gutmet 2018-12-23 15:51:20 +01:00
parent 18f9120c8c
commit 16cb002a8d

View File

@ -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) {
fmt.Print(question + ": ")
reader := bufio.NewReader(os.Stdin)