Solved

Copying Files in V C++

Posted on 1998-10-22
10
168 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
Comment Utility
Try the CopyFile() (or maybe MoveFile() and MoveFileEx()) windows API functions.

Let me know if you have questons.
0
 

Author Comment

by:jammop
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
Those pesky escape sequences :-)
0
 

Author Comment

by:jammop
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
Is this working for you?
0
 
LVL 22

Expert Comment

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

Expert Comment

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

Expert Comment

by:nietod
Comment Utility
Jammop, are you going to grade this?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

16 Experts available now in Live!

Get 1:1 Help Now