From 25f8a0cf225d45c8661e67d7cb4435ac866fe1d6 Mon Sep 17 00:00:00 2001 From: Amrit Panesar Date: Sun, 4 Oct 2020 13:37:29 -0700 Subject: [PATCH] update csv report for @cmd276 --- .gitignore | 1 + .idea/FileCompare.iml | 8 ++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ main.go | 7 ++++++- 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .idea/FileCompare.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 66fd13c..688e157 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +FileCompare # Test binary, built with `go test -c` *.test diff --git a/.idea/FileCompare.iml b/.idea/FileCompare.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/FileCompare.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dbeac43 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.go b/main.go index d378a2e..daa019b 100644 --- a/main.go +++ b/main.go @@ -139,6 +139,7 @@ func main() { } func saveSummary(path string) { + fileExists, err := os.Stat(path) summaryFile, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { fmt.Println(err) @@ -146,11 +147,15 @@ func saveSummary(path string) { } defer summaryFile.Close() + if fileExists == nil { + summaryFile.WriteString(fmt.Sprintf("\"%s\",\"%s\",\"%s\",\"%s\"\n", "hash", "filepath", "bytes", "copies")) + } + for hash, files := range ds.Files { if len(files) > 1 { // _, err := summaryFile.WriteString(fmt.Sprintf("%s - %s Duplicates", hash, len(files))) for _, file := range files { - summaryFile.WriteString(fmt.Sprintf("\"%s\",\"%s\"\n", hash, filepath.Join(file.Filepath, file.Filename))) + summaryFile.WriteString(fmt.Sprintf("\"%s\",\"%s\",\"%d\",\"%d\"\n", hash, filepath.Join(file.Filepath, file.Filename), file.Filesize, len(files))) } } }