Menu Close

Go – SameFile() function in os package in go

In this tutorial, we are going to learn about SameFile() function in os package in go. SameFile() function returns whether two files describe the same.

On the different machines, decision may vary based on file path name.

Function proto type:

func SameFile(fi1, fi2 FileInfo) bool

Return Value:

SameFile() function in os package returns
true when both the files describe the same
else false.

Example with code:

package main

import (



func main() {

  file_1, err_1 := os.Stat("golang.txt")

  if err_1 != nil {



  file_2, err_2 := os.Stat("go.txt")

  if err_2 != nil {



  res := os.SameFile(file_1, file_2)




$ go run sample.go

To learn more about golang, Please refer given below link:

Posted in golang, os

Leave a Reply

Your email address will not be published. Required fields are marked *