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
+7.8k Golang : Randomize letters from a string example
+11.1k Golang : Fuzzy string search or approximate string matching example
+4.4k PHP : Extract part of a string starting from the middle
+12.2k Golang : zlib compress file example
+11.5k Golang : Detect user location with HTML5 geo-location
+16.6k Golang : Find file size(disk usage) with filepath.Walk
+29.9k Golang : Remove characters from string example
+8k Your page has meta tags in the body instead of the head
+7.5k Javascript : Put image into Chrome browser's console
+7.7k How to show different content from website server when AdBlock is detected?