Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
September 19th, 2002, 11:56 PM
 Optix
Contributing User

Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
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
September 20th, 2002, 03:54 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,390
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 32 m 40 sec
Reputation Power: 4080
See the CopyFile() and CopyFileEx() documentation in MSDN

There should be no problems in using spaces in filenames with these functions.

#3
September 21st, 2002, 02:38 PM
 Optix
Contributing User

Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
oh sweet thanks

#4
September 23rd, 2002, 08:42 PM
 Optix
Contributing User

Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
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
September 23rd, 2002, 09:03 PM
 Beans4You
Some day I will be a Lambda!

Join Date: Jun 2002
Location: NJ
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
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
September 23rd, 2002, 11:41 PM
 Optix
Contributing User

Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
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
September 24th, 2002, 07:04 AM
 Beans4You
Some day I will be a Lambda!

Join Date: Jun 2002
Location: NJ
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
Here is a good example...

MSDN

Eric

#8
September 24th, 2002, 06:37 PM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,390
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 32 m 40 sec
Reputation Power: 4080
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
September 24th, 2002, 08:47 PM
 Optix
Contributing User

Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
Ok, Thanks a lot

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Copy a file?