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
+4.2k Linux/MacOSX : Search and delete files by extension
+9.4k Golang : interface - when and where to use examples
+8.6k Golang : HTTP Routing with Goji example
+17.4k Golang : Iterate linked list example
+4.6k Python : Find out the variable type and determine the type with simple test
+6.9k Golang : Validate credit card example
+18.3k Golang : Implement getters and setters
+20.9k Golang : How to get time zone and load different time zone?
+8.7k Golang : How to capture return values from goroutines?
+14.2k Golang : Reset buffer example
+12.9k Golang : Convert(cast) int to int64
+7.6k Golang : Gomobile init produce "iphoneos" cannot be located error