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
+15.5k Golang : Get all local users and print out their home directory, description and group id
+22k Golang : Use TLS version 1.2 and enforce server security configuration over client
+6.4k Golang : Selection sort example
+20.7k Golang : Secure(TLS) connection between server and client
+14k Golang : How to check if a file is hidden?
+20.2k Golang : Count number of digits from given integer value
+34k Golang : Call a function after some delay(time.Sleep and Tick)
+5.3k JavaScript/JQuery : Redirect page examples
+6.6k Unix/Linux : How to get own IP address ?
+19.2k Mac OSX : Homebrew and Golang
+7.5k Golang : How to detect if a sentence ends with a punctuation?