Skip to content

Instantly share code, notes, and snippets.

@rustysys-dev
Last active March 6, 2019 02:10
Show Gist options
  • Save rustysys-dev/bfe6abb322fceddd721a1598a6645cf7 to your computer and use it in GitHub Desktop.
Save rustysys-dev/bfe6abb322fceddd721a1598a6645cf7 to your computer and use it in GitHub Desktop.
Find all dirs in given directory.
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
)
func visit(path string, f os.FileInfo, err error) error {
r, _ := regexp.Compile(`(^.*/\..*$)`)
if f.IsDir() {
match := r.MatchString(path)
if match != true {
fmt.Printf("%s\n", path)
return nil
}
}
return nil
}
func main() {
flag.Parse()
root := flag.Arg(0)
err := filepath.Walk(root, visit)
if err != nil {
fmt.Printf("filepath.Walk() returned %v\n", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment