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
+35.6k Golang : Smarter Error Handling with strings.Contains()
+9.6k Golang : Validate IPv6 example
+9.4k Golang : Timeout example
+13.1k Golang : Calculate elapsed years or months since a date
+9.7k Golang : How to generate Code 39 barcode?
+18.6k Golang : Set, Get and List environment variables
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+25.3k Golang : Convert uint value to string type
+18.3k Golang : Get path name to current directory or folder
+12.4k Golang : Encrypt and decrypt data with x509 crypto
+8.2k Golang : Tell color name with OpenCV example