copying files

Hi everyone!!!
I wanna write a program, that copies a file from one location to another (for example copies D:\\file.txt to C:\\Folder1). Could u write the code???
I think Batch files are good for this, just google .bat commands.
Last edited on
I can tell you the function which can do this:

CopyFile(); //this works on windows, copies file from one location to other.
rename(); //this is standard c library function. moves file from one location to other

so you can do this:
CopyFile("D:\\file.txt","C:\\Folder1",TRUE);
TRUE means if the file is already existing it will not overwrite, making it FALSE will overwrite the file.
C++ is very good for reading and writing files, as far as the standard library goes, but for other things like copying, moving, etc. as far as i know it is better to use the system API, which will make your code platform dependent, but only for most of the file handling part.

I think that the Boost library may have something that is cross platform for doing other stuff with files, besides reading and writing, but i don't know how will the operating system feel if you try to move a file from a place to another place, it might think it is a virus or something, depending on the operating system, and it might block the access anyway.So i'm not so sure about Boost.
Topic archived. No new replies allowed.