Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gepser/c999c105bba348ee6fd89954efa6487b to your computer and use it in GitHub Desktop.
Save gepser/c999c105bba348ee6fd89954efa6487b 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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment