Created
November 17, 2012 21:38
-
-
Save robyoung/4100502 to your computer and use it in GitHub Desktop.
Find files generator
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 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