1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
36
Rep Power
16

#### Copy a file?

Hi i was wondering if anyone knew how I can copy a file (with C++) and then place it in a folder and overwrite a file in that folder with the same name.

Thanks

Edit: Oh yea, and i was wondering how i could open a file that has a space in the folder name like.. C:\Documents and Settings\default\My Documents how can i write that in C++ Coz it doesnt let me do spaces :(
2. See the CopyFile() and CopyFileEx() documentation in MSDN

There should be no problems in using spaces in filenames with these functions.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
36
Rep Power
16
oh sweet thanks
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
36
Rep Power
16
Hi, Sorry if i should newb but in order to copy a file, i have this code..

Code:
BOOL CopyFile(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName,
BOOL bFailIfExists
);
but... do i just leave lpExistingFileName as that? or do i change it with like C:\Whatever\I\Want\To\Copy

-Kyle
5. My experience, which is limited, is that you need to use double backslashes because of real expressions.
Example: C:\\Whatever\\I\\Want\\To\\Copy

Eric
6. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
36
Rep Power
16
Yea i know but what i mean is like how do i tell the program the path to the file? do i go like

#define lpExistingFileName C:\\*******

or what ?

Thanks.
7. Here is a good example...

MSDN

Eric
8. You can just use something like this:
Code:
CopyFile("C:\\path\\to\\source\\file", "C:\\path\\to\\destination\\file", FALSE);
If you don't understand what this LPCTSTR business is all about, I suggest you research Hungarian Notation on the web, or look it up in a Visual C++ programming book. Practically all of Micro\$oft's code uses Hungarian Notation as their standard naming convention and it's good to become slightly familiar with it.
9. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2002
Posts
36
Rep Power
16
Ok, Thanks a lot :D