Skip to content

Instantly share code, notes, and snippets.

@kashcode
Last active October 27, 2017 13:56
Show Gist options
  • Save kashcode/2a8901261d5d81385335d5e82cbee11a to your computer and use it in GitHub Desktop.
Save kashcode/2a8901261d5d81385335d5e82cbee11a to your computer and use it in GitHub Desktop.
go search wher what
package main
import (
"fmt"
"os"
"path"
"path/filepath"
"time"
)
func main() {
now := time.Now().UTC()
list := search(path.Join(os.Getenv("AppData"), "Mozilla", "Firefox", "Profiles"), "cert8.db")
for _, p := range list {
fmt.Printf("%s\n", filepath.Dir(p))
}
fmt.Println("took time: ", time.Since(now))
}
func search(where string, what string) []string {
list := make([]string, 0, 10)
err := filepath.Walk(where, func(path string, info os.FileInfo, err error) error {
if err == nil {
if filepath.Base(path) == what {
list = append(list, path)
}
}
return nil
})
if err != nil {
fmt.Printf("walk error [%v]\n", err)
}
return list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment