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
+16.8k Golang : Get own process identifier
+13.5k Golang : Read XML elements data with xml.CharData example
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+12.7k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+7.4k Golang : Scanf function weird error in Windows
+6.9k Android Studio : Hello World example
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+40.1k Golang : UDP client server read write example
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+6.9k Golang : Muxing with Martini example