Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy and Delete

Posted on 2002-06-21
4
Medium Priority
?
228 Views
Last Modified: 2010-04-01
What's the best way to copy or delete a file using Win32/MFC? Somthing to accmoplish these commands:

copy filename1 filename2
del filename

I'm assuming that there is a better alternative to using a function to execute those commands in a shell [eg: system()].
0
Comment
Question by:qqqqqqqqq
  • 2
4 Comments
 

Expert Comment

by:duncanlatimer
ID: 7098456
delete should be:
int _unlink( const char *filename );
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 7098483
You can use CopyFile() API function

For delete you can use DeleteFile() API function

0
 
LVL 30

Expert Comment

by:Axter
ID: 7098489
For delete you can also use remove() function, which is part of the C/C++ standard.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7098877
If you want the animated "flying paper" with progress indicator, you also have the option of using SHFileOperation to copy.

If you use SHFileOperation to delete, the file will be put in the Recycle Bin.  DeleteFile() makes is gone immediately.

For example, to copy with SHFileOperation do something like:

SHFILEOPSTRUCT mSHFile;

mSHFile.hwnd = NULL;
mSHFile.wfunc = FO_COPY;

// Note that BOTH of these need to be DOUBLE NULL
// terminated since a LIST is possible
mSHFile.pFrom = "SOURCEFILENAME\0";
mSHFile.pTo = "DESTINATIONFILENAME\0";

SHFileOperation(&mSHFile);


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
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

783 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