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
+5.3k Swift : Convert string array to array example
+32.6k Golang : Regular Expression for alphanumeric and underscore
+14.1k Golang : Fix image: unknown format error
+7.4k Golang : Shuffle strings array
+13k Golang : Calculate elapsed years or months since a date
+19.8k Golang : Count JSON objects and convert to slice/array
+9.6k PHP : Get coordinates latitude/longitude from string
+11.9k Golang : Determine if time variables have same calendar day
+5.2k Responsive Google Adsense
+19.1k Golang : Delete item from slice based on index/key position
+9.8k Golang : Function wrapper that takes arguments and return result example
+31.3k Golang : bufio.NewReader.ReadLine to read file line by line