[Golang] Compare the Size of Two Files


This post shows how to check if the size of two files is the same. Use os.Stat [2] to read information (os.FileInfo) of file and check if the size is the same.

import (
      "os"
)

func isFileSameSize(path1, path2 string) (sameSize bool, err error) {
      f1, err := os.Stat(path1)
      if err != nil {
              return
      }
      f2, err := os.Stat(path2)
      if err != nil {
              return
      }
      sameSize = (f1.Size() == f2.Size())
      return
}

Tested on: Ubuntu Linux 17.10, Go 1.10

References:

[1]
[2]How to get file length in Go? - Stack Overflow