err := os.RemoveAll(filePath)
if err != nil {
fmt.Println("cannot delete the file", err)
return nil, err
}
Currently the above code is deleting the files having the read only(tried for 0444) file permissions.
Are there any particular file permissions, which won't allow me to delete the files or the folder?
The key thing is to have write permissions on the directory that contains the files as this example shows
package main
import (
"fmt"
"os"
)
func dostuff(p os.FileMode, n string) {
err := os.Mkdir(n, 0700) // make as writable
_, err = os.Create(n + "/a")
_, err = os.Create(n + "/b")
os.Chmod(n, p) // alter permissions to see what happens
err = os.RemoveAll(n)
if err != nil {
fmt.Println("cannot delete the file", err)
}
}
func main() {
dostuff(0700, "writeallowed")
dostuff(0400, "readonly")
}