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
+11.9k Golang : Split strings into command line arguments
+22.3k Generate checksum for a file in Go
+14.2k How to automatically restart your crashed Golang server
+5.7k AWS S3 : Prevent Hotlinking policy
+5.1k Golang : Get FX sentiment from website example
+25.5k Golang : How to read integer value from standard input ?
+6.1k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+6.8k Restart Apache or Nginx web server without password prompt
+7.1k Golang : Scanf function weird error in Windows
+11k Use systeminfo to find out installed Windows Hotfix(s) or updates
+10.8k Golang : Simple image viewer with Go-GTK