Solved

Copying Files in V C++

Posted on 1998-10-22
10
186 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

816 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now