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
+5.5k Golang : Struct field tags and what is their purpose?
+7.7k Javascript : Put image into Chrome browser's console
+17.4k Golang : Read data from config file and assign to variables
+12.2k Elastic Search : Return all records (higher than default 10)
+8.7k Golang : Sort lines of text example
+11.8k Golang : Pagination with go-paginator configuration example
+16.2k CodeIgniter/PHP : Create directory if does not exist example
+9.4k Golang : Copy map(hash table) example
+19.3k Golang : Example for DSA(Digital Signature Algorithm) package functions
+52k Golang : How to get struct field and value by name
+9.2k Golang : Convert(cast) string to int64
+14.5k Golang : Find commonalities in two slices or arrays example