Golang : Change file read or write permission example
Problem :
You have a file and you need to change a file read, write or execute permission. How to achieve that?
Solutions :
Example 1:
// use Exec() function
cmd := exec.Command("chmod", "666", "file.txt")
out, err := cmd.Output()
Example 2:
// use os.Chmod() function.
err := os.Chmod("file.txt", 0777)
if err != nil {
fmt.Println(err)
}
See also : Golang : Test file read write permission example
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.2k Android Studio : Create custom icons for your application example
+23.3k Golang : Check if element exist in map
+9.9k Golang : Test a slice of integers for odd and even numbers
+14.4k Golang : Execute function at intervals or after some delay
+10k Golang : Detect number of faces or vehicles in a photo
+5.7k Golang : Function as an argument type example
+13.7k Golang : Get current time
+5.5k Swift : Get substring with rangeOfString() function example
+10k Golang : How to profile or log time spend on execution?
+19.2k Golang : How to count the number of repeated characters in a string?
+6.6k Golang : Get expvar(export variables) to work with multiplexer
+12.9k Golang : How to get a user home directory path?