Skip to content

Instantly share code, notes, and snippets.

@klashxx
Last active September 18, 2019 12:36
Show Gist options
  • Save klashxx/0781f9b2e68e15e487d25b664e9aec96 to your computer and use it in GitHub Desktop.
Save klashxx/0781f9b2e68e15e487d25b664e9aec96 to your computer and use it in GitHub Desktop.
func listDirectories(path string) ([]string, error) {
names := []string{}
items, err := ioutil.ReadDir(path)
if err != nil {
return names, err
}
for _, item := range items {
// We only want directories
if item.IsDir() {
currentDir := filepath.Join(path, item.Name())
names = append(names, currentDir)
// Do some recursion
subNames, err := listDirectories(currentDir)
if err == nil {
names = append(names, subNames...)
}
}
}
return names, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment