Skip to content

Instantly share code, notes, and snippets.

@francoishill
Created August 1, 2014 16:52
Show Gist options
  • Save francoishill/a5aca2a7bd598ef5b563 to your computer and use it in GitHub Desktop.
Save francoishill/a5aca2a7bd598ef5b563 to your computer and use it in GitHub Desktop.
Loop through files and folders recursively in golang
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() ([]string, error) {
searchDir := "c:/path/to/dir"
fileList := []string{}
err := filepath.Walk(searchDir, func(path string, f os.FileInfo, err error) error {
fileList = append(fileList, path)
return nil
})
for _, file := range fileList {
fmt.Println(file)
}
}
@0x113
Copy link

0x113 commented Oct 8, 2018

Thanks, very useful

Copy link

ghost commented Oct 12, 2018

@fubarhouse
no point in using make that I can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment