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
+6k Unix/Linux : How to open tar.gz file ?
+9.6k Golang : Get all countries currencies code in JSON format
+11.2k Golang : Fix go.exe is not compatible with the version of Windows you're running
+6k Golang : Denco multiplexer example
+7.1k Golang : Find the shortest line of text example
+39.8k Golang : Remove dashes(or any character) from string
+6.6k Golang : Totalize or add-up an array or slice example
+7.7k SSL : How to check if current certificate is sha1 or sha2 from command line
+10.2k Golang : Identifying Golang HTTP client request
+11.3k Google Maps URL parameters configuration
+6.9k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+5.3k Javascript : Change page title to get viewer attention