Golang : Change file read or write permission example



Tags : golang write-permission read-permission change-permissions

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)
 }

Affiliate :

Hire Golang Developers


  See also : Golang : Test file read write permission example



Tags : golang write-permission read-permission change-permissions

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