?
Solved

Copying Files in V C++

Posted on 1998-10-22
10
Medium Priority
?
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 260 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.
Suggested Courses

762 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