Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func exploreDirectory (path string, excludes []string) ([]string, error){
- var output []string
- //Get entries
- info, err := ioutil.ReadDir(path)
- if err != nil {
- return nil, err
- }
- for i, _ := range info {
- //Using a closure, to solve an issue with nested for loops.
- skip := func () bool {
- for _, exclude := range excludes {
- if exclude == path + "/" + info[i].Name() {
- return true
- }
- }
- return false
- }()
- if skip {
- continue
- }
- if !info[i].IsDir() {
- //Output file
- output = append(output, path + "/" + info[i].Name())
- } else {
- //Explore it; it's a directory.
- entries, err := exploreDirectory(path + "/" + info[i].Name(), excludes)
- if err != nil {
- return nil, err
- }
- output = append(output, entries...)
- }
- }
- return output, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement