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
+9.6k Golang : Load ASN1 encoded DSA public key PEM file example
+35.4k Golang : Integer is between a range
+11.9k Golang : Detect user location with HTML5 geo-location
+30.9k Golang : Calculate percentage change of two values
+16k Golang : Loop each day of the current month example
+8.1k Golang : HttpRouter multiplexer routing example
+12.1k Golang : How to check if a string starts or ends with certain characters or words?
+10.3k Swift : Convert (cast) String to Integer
+5k Golang : Check if a word is countable or not
+6.3k Golang : Handling image beyond OpenCV video capture boundary
+22k Golang : Convert seconds to minutes and remainder seconds
+18.1k Golang : How to remove certain lines from a file