Created
July 30, 2017 13:23
-
-
Save m-x-k/639213611df707ce49b13ddc87e564b5 to your computer and use it in GitHub Desktop.
Golang script to find folders with matching string
This file contains hidden or 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 ( | |
"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