Skip to main content
gamedev.net
🔒 Locked

Copy Command

Started by thannett Dec 4, 2004 at 11:53 AM 2 replies 350+ views
Original Post
thannett
thannett
Hi, I was wondering if there was a copy command in C++? I know that you can use system() calls, but I want to copy to a directory that I have created, but whose name will change daily. I have the name of the directory stored in a string variable. Sorry if I was not clear. Thanks!
ToohrVyk
ToohrVyk
Well, if you know what the name is, all you have to do is compute the command at runtime, and pass it to system.

Such as:

#include <string>using std::string;//...string sourcedir = "/usr/local/";string objname = "stuff.txt";string destination = "/usr/backup/";//...string command = string("cp ") + sourcedir + objname + " " + destination + objname;system( command.c_str( ) );
Oluseyi
Oluseyi
The most efficient means are platform specific. That said, however, you can achieve the same effect as follows:
#include <algorithm>#include <fstream>#include <iostream>#include <iterator>int main(int argc, char * argv[]){  // arg 1: path to source file  // arg 2: path to dest file  //*** assume data validation  using namespace std;  ifstream fin(argv[1]);  ofstream fout(argv[2]);  istream_iterator<char> isi(fin), eos;  ostream_iterator<char> osi(fout);  copy(isi, eos, osi);  fout.close();  fin.close();  return 0;}
thannett
thannett
Thanks guys!!!!

I ended up using ToohrVyk's solution, mainly because I'm not the greatest programmer and it took less time for me to understand.

Anyways, Thank you both very much!!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.