{"id":2053,"date":"2020-04-17T20:40:12","date_gmt":"2020-04-17T20:40:12","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=2053"},"modified":"2020-04-18T05:47:57","modified_gmt":"2020-04-18T05:47:57","slug":"change-current-working-directory-go","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/change-current-working-directory-go\/","title":{"rendered":"cd command in Go or change current working directory in Go (Golang)"},"content":{"rendered":"\n
Overview<\/strong><\/p>\n\n\n\n os.Chdir() <\/strong>is used to change the current working directory to the named directory in golang. It is similar to the cd command. 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 Overview os.Chdir() is used to change the current working directory to the named directory in golang. It is similar to the cd command. 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":[288,3,4],"class_list":["post-2053","post","type-post","status-publish","format-standard","hentry","category-tech","tag-cd-command","tag-go","tag-golang"],"yoast_head":"\n
<\/p>\n\n\n\nfunc Chdir(dir string) error<\/code><\/pre>\n\n\n\n
package main\n\nimport (\n \"fmt\"\n \"os\"\n)\n\nfunc main() {\n os.Chdir(\"\/Users\")\n newDir, err := os.Getwd()\n if err != nil {\n }\n fmt.Printf(\"Current Working Direcotry: %s\\n\", newDir)\n}<\/code><\/pre>\n\n\n\n
Current Working Direcoty: \/Users<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"