Skip to content

Instantly share code, notes, and snippets.

@juliakm
Created February 18, 2020 19:22
Show Gist options
  • Save juliakm/47584fb0dfe2461dd7ef28007d5cb5a4 to your computer and use it in GitHub Desktop.
Save juliakm/47584fb0dfe2461dd7ef28007d5cb5a4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
)
func visit(files *[]string) filepath.WalkFunc {
return func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Fatal(err)
}
if strings.Contains(path, "includes") {
*files = append(*files, path)
}
return nil
}
}
func main() {
var files []string
root := "/my/file/path/azure-devops-docs-pr/docs/pipelines"
err := filepath.Walk(root, visit(&files))
if err != nil {
panic(err)
}
for _, file := range files {
fmt.Println(file)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment