Move File Functions

On same drive
	string source_path;
	string dest_path;
	source_path = "/home/pi/file_oldname";
	dest_path = "/home/pi/file_newname";
	rename(source_path.c_str(), dest_path.c_str());
To an external drive

Moving between file systems is not possible with rename() 

	string source_path;
	string dest_path;
	source_path = "/home/pi/file_oldname";
	dest_path = "/home/pi/file_newname";
	ifstream ifstream1(source_path.c_str(), ios::in | ios::binary);
	ofstream ofstream1(dest_path.c_str(), ios::out | ios::binary);
	ofstream1 << ifstream1.rdbuf();
	remove(source_path.c_str());

Move Multiple Files Using A Command

#define DB_FILEIO_DIRECTORY_1	"/home/pi/myfolder1"
#define DB_FILEIO_DIRECTORY_2	"/home/pi/myfolder2"

	string CommandString;

	//Example command: "mv /path/sourcefolder/* /path/destinationfolder/"
	CommandString = "mv ";
	CommandString += DB_FILEIO_DIRECTORY_1;
	CommandString += "/*.txt ";	//Use this for all files: "/* "
	CommandString += DB_FILEIO_DIRECTORY_2;
	CommandString += "/";
	system(CommandString.c_str());
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *