Last active
October 27, 2017 13:56
-
-
Save kashcode/2a8901261d5d81385335d5e82cbee11a to your computer and use it in GitHub Desktop.
go search wher what
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 ( | |
"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