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
+16k Golang : Qt image viewer example
+13k Golang : Recombine chunked files example
+4.4k Javascript : How to loop over and parse JSON data?
+7.8k Golang : How to use Gorilla webtoolkit context package properly
+15.8k Golang : Get future or past hours, minutes or seconds
+5.5k Golang : How to validate ISBN?
+5.7k Default cipher that OpenSSL used to encrypt a PEM file
+29.1k Golang : How to redirect to new page with net/http?
+31k Golang : Smarter Error Handling with strings.Contains()
+8.4k Golang : Qt get screen resolution and display on center example
+7.9k Golang : Populate or initialize struct with values example
+8.4k Golang : Format strings to SEO friendly URL example