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
+5.7k PHP : Convert CSV to JSON with YQL example
+12.6k Golang : How to check if a string starts or ends with certain characters or words?
+7.6k Golang : Check to see if *File is a file or directory
+5.6k Golang : Reclaim memory occupied by make() example
+6.7k PHP : Shuffle to display different content or advertisement
+20.4k Golang : How to get struct tag and use field name to retrieve data?
+13.5k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+7.6k Golang : Convert source code to assembly language
+13k Golang : http.Get example
+7.8k Golang : get the current working directory of a running program
+22.9k Generate checksum for a file in Go
+7.6k Golang : Individual and total number of words counter example