Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created July 30, 2017 13:23
Show Gist options
  • Save m-x-k/639213611df707ce49b13ddc87e564b5 to your computer and use it in GitHub Desktop.
Save m-x-k/639213611df707ce49b13ddc87e564b5 to your computer and use it in GitHub Desktop.
Golang script to find folders with matching string
package main
import (
"os"
"log"
"path/filepath"
"strings"
)
func findFolderLike(dir string, match string) {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
var name = filepath.Base(path)
var check = strings.Contains(name, match)
if check == true {
log.Print(path)
}
return nil
})
if err != nil {
log.Fatal(err)
}
}
func main() {
log.SetFlags(log.Lshortfile)
// go run findFolderLike.go <DIR> <MATCH_STRING>
dir := os.Args[1]
match := os.Args[2]
findFolderLike(dir, match)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment