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
+6.7k Mac OSX : Find large files by size
+19.6k Golang : Archive directory with tar and gzip
+14.2k Android Studio : Use image as AlertDialog title with custom layout example
+10k Golang : Print how to use flag for your application example
+11.5k Golang : Convert(cast) float to int
+6.7k Default cipher that OpenSSL used to encrypt a PEM file
+9.5k Golang : Sort and reverse sort a slice of floats
+27.4k PHP : Convert(cast) string to bigInt
+20k Golang : Count number of digits from given integer value
+10.9k How to test Facebook App on localhost ?
+11.3k Golang : Handle API query by curl with Gorilla Queries example
+8.4k Golang : Another camera capture GUI application with GTK and OpenCV