Golang : Get file permission
Get a file permission in Go is easy. In this tutorial, we will see how to read a file permission and display the permission. This example will use the http://golang.org/pkg/os/#File.Stat function.
getfilepermission.go
package main
import (
"fmt"
"os"
)
func main() {
file := "file.txt"
info,_ := os.Stat(file)
mode := info.Mode()
fmt.Println(file, "mode is " , mode)
}
Test this code out and see the output of file permission.
You should see something similar to this example output :
> go run getfilepermission.go
file.txt mode is -rw-rw-r--
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+28.2k Golang : Get time.Duration in year, month, week or day
+24.7k Mac/Linux and Golang : Fix bind: address already in use error
+50.6k Golang : How to get time in milliseconds?
+12.2k Golang : Read XML elements data with xml.CharData example
+6.1k Golang : Transform lisp or spinal case to Pascal case example
+8.3k Golang : Temperatures conversion example
+18.3k Golang : How to Set or Add Header http.ResponseWriter?
+14.5k Golang : Loop each day of the current month example
+7.2k Golang : How To Use Panic and Recover
+6.6k Golang : Convert(cast) io.Reader type to string
+10.3k Golang : Post data with url.Values{}
+16.2k Golang : Parse date string and convert to dd-mm-yyyy format