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
+9.5k Golang : ffmpeg with os/exec.Command() returns non-zero status
+25.4k Golang : missing Mercurial command
+10.3k Golang : How to delete element(data) from map ?
+6.3k Golang : Embedded or data bundling example
+6.5k How to let Facebook Login button redirect to a particular URL ?
+4.8k Linux : How to set root password in Linux Mint
+5.8k Golang : Grab news article text and use NLP to get each paragraph's sentences
+37k Upload multiple files with Go
+22.6k Golang : Calculate time different
+40.7k Golang : How to count duplicate items in slice/array?
+6.9k Golang : Dealing with postal or zip code example
+16.1k Golang : Get IP addresses of a domain name