The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Copy a file?
Discuss Copy a file? in the C Programming forum on Dev Shed. Copy a file? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 19th, 2002, 11:56 PM
|
|
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 
|

September 20th, 2002, 03:54 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
See the CopyFile() and CopyFileEx() documentation in MSDN
There should be no problems in using spaces in filenames with these functions.
|

September 21st, 2002, 02:38 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
oh sweet thanks
|

September 23rd, 2002, 08:42 PM
|
|
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
Thanks in advance.
-Kyle
|

September 23rd, 2002, 09:03 PM
|
 |
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
|

September 23rd, 2002, 11:41 PM
|
|
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.
|

September 24th, 2002, 07:04 AM
|
 |
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
|

September 24th, 2002, 06:37 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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.
|

September 24th, 2002, 08:47 PM
|
|
Contributing User
|
|
Join Date: Jun 2002
Posts: 36
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Ok, Thanks a lot 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|