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
+2.3k Javascript : How to loop over and parse JSON data?
759 Golang : How to check if a website is served via HTTPS
+5.6k Golang : Reset buffer example
+5.7k Android Studio : Highlight ImageButton when pressed on example
+5.5k Golang : Find commonalities in two slices or arrays example
+4.6k Golang : Convert int(year) to time.Time type
+9.2k Golang : Join arrays or slices example
+3.1k Golang : Create unique title slugs example
+1.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+2.7k Golang : How to deal with configuration data?
+2.1k Golang : Accessing dataframe-go element by row, column and name example
+3.3k Elasticsearch : Shutdown a local node