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.9k nginx: [emerg] unknown directive "passenger_enabled"
+20.7k Golang : How to reverse slice or array elements order
+8.5k Golang : Accessing content anonymously with Tor
+6.8k Golang : How to execute code at certain day, hour and minute?
+27.9k Golang : How to create new XML file ?
+28.6k Golang : How to verify uploaded file is image or allowed file types
+13.8k Golang : Basic authentication with .htpasswd file
+27.9k Golang : Save map/struct to JSON or XML file
+8k Golang : Find the length of big.Int variable example
+4.2k Python : Convert(cast) bytes to string example
+5.4k CodeIgniter : form input set_value cause " to become & quot
+11.2k Golang : Forwarding a local port to a remote server example