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
+46.7k Golang : Marshal and unmarshal json.RawMessage struct example
+5.5k Golang *File points to a file or directory ?
+6.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+52k Golang : How to get time in milliseconds?
+19.3k Golang : Delete item from slice based on index/key position
+19.9k Golang : Append content to a file
+13.5k Golang : Linear algebra and matrix calculation example
+26.7k Golang : Encrypt and decrypt data with AES crypto
+38.3k Golang : Read a text file and replace certain words
+9.4k Golang : How to check if a string with spaces in between is numeric?
+14.1k Golang : Get dimension(width and height) of image file
+41.4k Golang : How to count duplicate items in slice/array?