Solved

Copying Files in V C++

Posted on 1998-10-22
10
193 Views
Last Modified: 2010-04-02
I would like to copy a file from one folder to another. I need to be able to specify a full UNC path. What functions, if any, does Vc++ supply to do this?
Thanks for any help;
0
Comment
Question by:jammop
10 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 130 total points
ID: 1175800
Try the CopyFile() (or maybe MoveFile() and MoveFileEx()) windows API functions.

Let me know if you have questons.
0
 

Author Comment

by:jammop
ID: 1175801
I've tried these functions but they don't seem to work for what I need.
I'd like to be able to write:
copyfile("\\serv01\directory\file.txt","C:\dest\");
Have I made a mistake, do the files you suggested work for this?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175802
If that is exectly what you had in your code, then the problem is not the function.

You must use two \'s inside a string "literal" to represent a single \.

Thus you would need

copyfile("\\\\serv01\\directory\\file.txt","C:\\dest\\")

Is that the problem?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:thresher_shark
ID: 1175803
Those pesky escape sequences :-)
0
 

Author Comment

by:jammop
ID: 1175804
That'd be the problem.
Sorry, another problem as well:
I tried using two cstrings for the files but it doesn't seem to work. Is there CString member function which will convert the Cstring so that copyfile will work? I can't seem to find one. Thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175805
The CString c;ass has a conversion to LPCSTR operator.  That should be invoked automatically, thus there should be no problem.

Note for this to work, you must specify the CStrign object to the function, not a pointer to one.  The object will be converted to a pointer to a NUL terminated string.  (If you specify a pointer to a CString this won't happen.)


0
 
LVL 22

Expert Comment

by:nietod
ID: 1175806
Is this working for you?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175807
Do you still need help on this, or is it working?
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1175808
I had that same problem two days ago ;) happens to the best of us.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175809
Jammop, are you going to grade this?
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question