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 (

  "fmt"
  "os"

)

func main() {


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

  if err_1 != nil {

    panic(err_1)

  }

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

  if err_2 != nil {

    panic(err_2)

  }

  res := os.SameFile(file_1, file_2)

  fmt.Println(res)

}

Output:

$ go run sample.go
false

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

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, os

Leave a Reply

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