{"id":3283,"date":"2020-07-23T12:55:50","date_gmt":"2020-07-23T12:55:50","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=3283"},"modified":"2020-07-23T13:09:42","modified_gmt":"2020-07-23T13:09:42","slug":"move-file","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/file-input-and-output\/working-with-files\/move-file","title":{"rendered":"Move File"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Move File Functions<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">On same drive<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\tstring source_path;\n\tstring dest_path;\n\tsource_path = \"\/home\/pi\/file_oldname\";\n\tdest_path = \"\/home\/pi\/file_newname\";\n\trename(source_path.c_str(), dest_path.c_str());<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">To an external drive<\/h5>\n\n\n\n<p>Moving between file systems is not possible with rename()&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tstring source_path;\n\tstring dest_path;\n\tsource_path = \"\/home\/pi\/file_oldname\";\n\tdest_path = \"\/home\/pi\/file_newname\";\n\tifstream ifstream1(source_path.c_str(), ios::in | ios::binary);\n\tofstream ofstream1(dest_path.c_str(), ios::out | ios::binary);\n\tofstream1 &lt;&lt; ifstream1.rdbuf();\n\tremove(source_path.c_str());<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Move Multiple Files Using A Command<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#define DB_FILEIO_DIRECTORY_1\t\"\/home\/pi\/myfolder1\"\n#define DB_FILEIO_DIRECTORY_2\t\"\/home\/pi\/myfolder2\"\n\n\tstring CommandString;\n\n\t\/\/Example command: \"mv \/path\/sourcefolder\/* \/path\/destinationfolder\/\"\n\tCommandString = \"mv \";\n\tCommandString += DB_FILEIO_DIRECTORY_1;\n\tCommandString += \"\/*.txt \";\t\/\/Use this for all files: \"\/* \"\n\tCommandString += DB_FILEIO_DIRECTORY_2;\n\tCommandString += \"\/\";\n\tsystem(CommandString.c_str());<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Move File Functions On same drive To an external drive Moving between file systems is not possible with rename()&nbsp; Move Multiple Files Using A Command<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[],"class_list":["post-3283","post","type-post","status-publish","format-standard","hentry","category-working-with-files"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=3283"}],"version-history":[{"count":4,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3283\/revisions"}],"predecessor-version":[{"id":3296,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3283\/revisions\/3296"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=3283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=3283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=3283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}