{"id":1433,"date":"2020-02-22T09:18:50","date_gmt":"2020-02-22T09:18:50","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=1433"},"modified":"2020-04-16T06:41:20","modified_gmt":"2020-04-16T06:41:20","slug":"move-file-from-one-location-to-another-golang","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/move-file-from-one-location-to-another-golang\/","title":{"rendered":"Move file from one location to another in or command mv in Go (Golang)"},"content":{"rendered":"\n
os.Rename() function can be used to mv or move a file from one location to another. It is equivalent to command ‘mv’<\/strong> of Linux. Below is the signature of the function<\/p>\n\n\n\n Code:<\/strong><\/p>\n\n\n\n os.Rename() function can be used to mv or move a file from one location to another. It is equivalent to command ‘mv’ of Linux. Below is the signature of the function Code:<\/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":[],"class_list":["post-1433","post","type-post","status-publish","format-standard","hentry","category-tech"],"yoast_head":"\nfunc Rename(oldpath, newpath string) error<\/code><\/pre>\n\n\n\n
package main\n\nimport (\n \"log\"\n \"os\"\n)\n\nfunc main() {\n \/\/Create a file\n file, err := os.Create(\"temp.txt\")\n if err != nil {\n log.Fatal(err)\n }\n defer file.Close()\n\n \/\/Change permission so that it can be moved\n err = os.Chmod(\"temp.txt\", 0777)\n if err != nil {\n log.Println(err)\n }\n\n newLocation := \"~\/Desktop\/temp.txt\"\n err = os.Rename(\"temp.txt\", newLocation)\n if err != nil {\n log.Fatal(err)\n }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"