Skip to content

Instantly share code, notes, and snippets.

@raoulduke
Last active March 9, 2018 17:57
Show Gist options
  • Save raoulduke/8f34527810696ed84c9a6a254d699a94 to your computer and use it in GitHub Desktop.
Save raoulduke/8f34527810696ed84c9a6a254d699a94 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"path/filepath"
"regexp"
)
func main() {
fmt.Println(findFiles("test"))
}
func findFiles(name string, dir string) []string {
searchPath := filepath.FromSlash(dir)
var files []string
filepath.Walk(searchPath, func(path string, f os.FileInfo, _ error) error {
if !f.IsDir() {
match, err := regexp.MatchString(name, f.Name())
if err == nil && match {
files = append(files, f.Name())
}
}
return nil
})
return files
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment