Skip to content

Instantly share code, notes, and snippets.

@robyoung
Created November 17, 2012 21:38
Show Gist options
  • Save robyoung/4100502 to your computer and use it in GitHub Desktop.
Save robyoung/4100502 to your computer and use it in GitHub Desktop.
Find files generator
func findFiles(paths []string) <-chan string {
files := make(chan string)
// Start a go routine to feed the channel
go func(files chan <- string, paths []string) {
// Walk the filesystem for each path, calling the annonymous
// function provided for each subpath.
for _, path := range paths {
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
// Do not send paths if they're directories
if !info.IsDir() {
files <- path
}
return nil
})
}
close(paths)
return
}(files, paths)
return files
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment