Live data from Hacker News

A tiny file comparison program written in Go

github.com

1–5 of 5 posts

Re: A tiny file comparison program written in Go

#2
I made a similar utility a while back to help trim down my family photos library that had many duplicates [0]. I took the approach of a dry-run option and an option to go ahead and delete duplicate files too. It also traverses the folder recursively, to get all files in a tree.

[0] https://github.com/MatanSilver/rmdupes

Re: A tiny file comparison program written in Go

#3

    log.Print("Missing argument for files direcory, Exiting...")
    os.Exit(0)
Exit code 0 is usually used for success. This is clearly an error.

    filePath + "/" + file.Name()
There's path/filepath module for cross-platform joining of file paths.

Don't use defer f.Close() in the loop — defer will execute after the function returns. What you're doing is opening all of the files in the directory and then closing them only when the program exists.

     if file.IsDir() == false {
Already boolean, this should be

     if !file.IsDir() {
Apart from all of this, it looks like the algorithm is very inefficient with all of those slice manipulations.

Re: A tiny file comparison program written in Go

#4
post #3

log.Print("Missing argument for files direcory, Exiting...") os.Exit(0) Exit code 0 is usually used for success. This is clearly an error. filePath + "/" + file.Name() There's path/filepath module for cross-platform joining of file paths. Don't use defer f.Close() in the loop — defer will execute after the function returns. What you're doing is opening all of the files in the directory and then closing them only when…

Did some refactoring :) thanks for noticing ... It's now far more efficient from a small test I've did