Last active
March 9, 2018 17:57
-
-
Save raoulduke/8f34527810696ed84c9a6a254d699a94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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