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
+48.3k Golang : Upload file from web browser to server
+13.3k Golang : Strings comparison
+11.5k Golang : How to detect a server/machine network interface capabilities?
+15.4k Golang : How to convert(cast) IP address to string?
+12.4k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+11.9k Golang : Split strings into command line arguments
+8.1k Golang : Oanda bot with Telegram and RSI example
+6.4k Golang : How to validate ISBN?
+9k Golang : How to control fmt or log print format?
+10.8k Golang : Simple image viewer with Go-GTK
+6.6k Golang : Calculate pivot points for a cross
+37.7k Golang : Read a text file and replace certain words