?
Solved

Copying Files in V C++

Posted on 1998-10-22
10
Medium Priority
?
220 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

862 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