Hey everyone.. its been so long since i've posted here..
So my question is: Is there a way to copy a file from one location to another using variables?
I'd really appreciate the help- Oh, and i'm using Dev-C++ 4 as a compiler.
Thanks in advance!
Hey everyone.. its been so long since i've posted here..
So my question is: Is there a way to copy a file from one location to another using variables?
I'd really appreciate the help- Oh, and i'm using Dev-C++ 4 as a compiler.
Thanks in advance!
.
Probably. What are the variables supposed to do?
I may have explained that wrong.
Say i've got one variable containing the path of a file to be copied and another variable with the path of where it's supposed to be copied to.
Now all I need is to figure out how to copy it.
.
So, you could sprintf those paths into a string, and use it in a system() call.
Okay, I tried that.. but im totally confused on the sprintf() function. It's been so damn long since i've done anything in C++.
Here's what I tried:
All that sprintf is storing to my variable is the string "copy". Im totally lost.Code:char pathtocopyfrom[256]; char pathtocopyto[256]; char doit[256]; sprintf(doit, "copy ", pathtocopyfrom, pathtocopyto); printf(doit);
.
You need %s to denote where your string variable should go.
Code:const char source[] = "C:/SomeFile.txt"; const char dest[] = "D:/NewFile.txt"; char buffer[256]; sprintf( buffer, "copy %s %s", source, dest ); system( buffer );
FYI: A google on "C++ sprintf" only returned 1,060,000 hits. And technically, this is really C; I imagine the C++ people would actually use a stringstream or similar.Code:sprintf(doit, "copy %s %s", pathtocopyfrom, pathtocopyto);
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Use the CopyFile API, or better yet, use boost::filesystem::copy.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law