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
+8.4k Golang : Convert(cast) string to int64
+21.6k Golang : Strings to lowercase and uppercase example
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+19.1k Golang : How to force compile or remove object files first before rebuild?
+5.5k Android Studio : Hello World example
+13.3k Golang : Parsing or breaking down URL
+12.9k Golang : Check if a file exist or not
+32.5k Golang : Call a function after some delay(time.Sleep and Tick)
+6.7k Golang : Ways to recover memory during run time.
+8.2k Golang : Scramble and unscramble text message by randomly replacing words
+7.7k Golang : Gorilla web tool kit schema example
+8.8k PHP : Get coordinates latitude/longitude from string