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
+16.2k Golang : Linked list example
+16.5k Golang : Put UTF8 text on OpenCV video capture image frame
+19.9k Golang : How to get time zone and load different time zone?
+11.2k Golang : How to check if a string starts or ends with certain characters or words?
+14.5k Golang : Read large file with bufio.Scanner cause token too long error
+3.5k Java : Generate multiplication table example
+32.7k Golang : convert(cast) bytes to string
+5.6k Golang : Gargish-English language translator
+9.1k Golang : Read file and convert content to string
+6.4k Golang : How to convert strange string to JSON with json.MarshalIndent
+10.8k Golang : Determine if time variables have same calendar day
+6.2k Golang : Of hash table and hash map