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
+21.1k Golang : Securing password with salt
+7.3k Golang : HttpRouter multiplexer routing example
+5.1k Golang : Shuffle array of list
+8.5k Golang : Web(Javascript) to server-side websocket example
+6.3k Golang : Accessing dataframe-go element by row, column and name example
+9.8k Golang : How to delete element(data) from map ?
+35.4k Golang : Display float in 2 decimal points and rounding up or down
+8.4k Golang : does not implement flag.Value (missing Set method)
+20.9k Golang : How to reverse slice or array elements order
+31.6k Golang : How to check if a date is within certain range?
+17.1k Golang : Aligning strings to right, left and center with fill example
+9.7k JavaScript/JQuery : Detect or intercept enter key pressed example