Last active
September 18, 2019 12:36
-
-
Save klashxx/0781f9b2e68e15e487d25b664e9aec96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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