想简单去重一下拍的图片的,找了一下就看到博主这篇(只处理当前目录)了,结果还是自己动手了,如下:(两个Func都是直接Copy网上的)

func GetAllFile(dirpath string) ([]string, error) {
result := []string{}
fis, err := ioutil.ReadDir(dirpath)
if err != nil {
return result, err
}
for _, fi := range fis {
fullname := dirpath + "/" + fi.Name()
if fi.IsDir() {
temp, err := GetAllFile(fullname)
if err != nil {
return result, err
}
result = append(result, temp...)
} else {
result = append(result, fullname)
}
}
return result, nil
}

func Md5Sum(fullname string) (string, error) {
f, err := os.Open(fullname)
if err != nil {
return "", err
}
defer f.Close()
bs, err := ioutil.ReadAll(f)
if err != nil {
return "", err
}
md5 := fmt.Sprintf("%x", md5.Sum(bs))
runtime.GC()
return md5, nil
}

func main() {
md5Map := make(map[string][]string)
tmp := make(map[string]int)
dirpath := "H:/JPG/"
list, _ := GetAllFile(dirpath)
for _, v := range list {
md5, _ := Md5Sum(v)
if _, ok := md5Map[md5]; ok {
tmp[md5]++
}
md5Map[md5] = append(md5Map[md5], v)
}
for k, v := range tmp {
fmt.Println(md5Map[k], v)
}
}