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
+18.1k Golang : Generate thumbnails from images
+10k Android Studio : Checkbox for user to select options example
+9.8k Golang : How to profile or log time spend on execution?
+5.1k Golang : Stop goroutine without channel
+26.1k Golang : Convert file content into array of bytes
+13.4k Golang : Fix image: unknown format error
+15k Golang : Validate hostname
+9.8k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+9.5k Golang : Channels and buffered channels examples
+7.7k Golang : Tell color name with OpenCV example
+6.4k Golang : Gargish-English language translator
+17.5k Golang : Check if a directory exist or not