-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 764 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"log"
"os"
"path"
)
func main() {
readCurrentDir()
}
func readCurrentDir() {
dirname := os.Getenv("FOLDER_PATH")
file, err := os.Open(dirname)
if err != nil {
log.Fatalf("failed opening directory: %s", err)
}
defer file.Close()
list, _ := file.Readdirnames(0)
for _, files := range list { // list all files in directory and calcuate md5sum
apsoluteFilPath := path.Join(dirname, files)
f, err := os.Open(apsoluteFilPath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
// fmt.Printf("%x\n", h.Sum(nil))
fmt.Println("File: ", files, "md5sum: ", hex.EncodeToString(h.Sum(nil)))
}
}