Advertisement
pcwizz

Untitled

Nov 29th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.03 KB | None | 0 0
  1. func exploreDirectory (path string, excludes []string) ([]string, error){
  2.     var output []string
  3.     //Get entries
  4.     info, err := ioutil.ReadDir(path)
  5.     if err != nil {
  6.         return nil, err
  7.     }
  8.     for i, _ := range info {
  9.         //Using a closure, to solve an issue with nested for loops.
  10.         skip := func () bool {
  11.              for _, exclude := range excludes {
  12.                 if exclude == path + "/" + info[i].Name() {
  13.                     return true
  14.                 }
  15.             }
  16.             return false
  17.         }()
  18.         if skip {
  19.             continue
  20.         }
  21.         if !info[i].IsDir() {
  22.             //Output file
  23.             output = append(output, path + "/" + info[i].Name())
  24.         } else {
  25.             //Explore it; it's a directory.
  26.             entries, err := exploreDirectory(path + "/"  + info[i].Name(), excludes)
  27.             if err != nil {
  28.                 return nil, err
  29.             }
  30.             output = append(output, entries...)
  31.         }
  32.     }
  33.     return output, nil
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement