Skip to content

Instantly share code, notes, and snippets.

@Veejay Veejay/test.go
Created Jan 17, 2013

Embed
What would you like to do?
package main
import (
"fmt"
"net/http"
"strings"
"log"
"io/ioutil"
"path/filepath"
"os"
)
func WalkPathRecursively(path string, filepaths chan string, done chan bool) {
dir, err := os.Open(path)
defer dir.Close()
if err != nil {
// Do something with error here
}
contents, err := dir.Readdir(0)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, f := range contents {
if f.IsDir() {
WalkPathRecursively(filepath.Join(path, f.Name()), filepaths, done)
} else {
filepaths <- filepath.Join(path, f.Name())
}
}
close(filepaths)
done <- true
}
func main() {
dirName := "/some/path"
filepaths := make(chan string)
done := make(chan bool)
WalkPathRecursively(dirName, filepaths, done)
for {
select {
case msg := <-done:
close(done)
goto END
case msg, _ := <-filepaths:
fmt.Println(msg)
}
}
// Not sure if I need this
END:
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.