{"id":2036,"date":"2020-04-17T17:45:18","date_gmt":"2020-04-17T17:45:18","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=2036"},"modified":"2020-04-17T17:45:31","modified_gmt":"2020-04-17T17:45:31","slug":"change-folder-directory-permissions-go","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/change-folder-directory-permissions-go\/","title":{"rendered":"Change folder\/directory permissions in Go (Golang)"},"content":{"rendered":"\n
os.Chmod()<\/strong> function can be used to change the permissions of an existing folder or directory. Below is the signature of the function<\/p>\n\n\n\n Code<\/strong><\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n os.Chmod() function can be used to change the permissions of an existing folder or directory. Below is the signature of the function Code Output:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[154,272,3,4,280],"class_list":["post-2036","post","type-post","status-publish","format-standard","hentry","category-tech","tag-directory","tag-folder","tag-go","tag-golang","tag-permissions"],"yoast_head":"\nfunc Chmod(name string, mode FileMode) error<\/code><\/pre>\n\n\n\n
package main\n\nimport (\n \"fmt\"\n \"log\"\n \"os\"\n)\n\nfunc main() {\n err := os.Mkdir(\"new\", 0755)\n if err != nil {\n log.Fatal(err)\n }\n stats, err := os.Stat(\"new\")\n if err != nil {\n log.Fatal(err)\n }\n fmt.Printf(\"Permission Folder Before: %s\\n\", stats.Mode())\n err = os.Chmod(\"new\", 0700)\n if err != nil {\n log.Fatal(err)\n }\n stats, err = os.Stat(\"new\")\n if err != nil {\n log.Fatal(err)\n }\n fmt.Printf(\"Permission Folder After: %s\\n\", stats.Mode())\n}<\/code><\/pre>\n\n\n\n
Permission Folder Before: drwxr-xr-x\nPermission Folder After: drwx------<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"