Home >Backend Development >Golang >GoLang os.Chdir() permission denied
I'm writing a program that creates a directory and then changes the working directory to the newly created directory to perform some work:
func main() { err := os.mkdir("english", 0777) // i know 777 is not good practice, first i want to get chdir() working if err != nil && !os.isexist(err) { log.fatal(err) } err = os.chdir("english") if err != nil { log.fatal(err) } }
Console output:
023/02/05 18:15:45 chdir English: permission denied exit status 1
Simple fix: Executing the program with sudo
causes the directory to be created with the specified permissions.
The above is the detailed content of GoLang os.Chdir() permission denied. For more information, please follow other related articles on the PHP Chinese website!