Solved

Copy and Delete

Posted on 2002-06-21
4
226 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
[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
  • 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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 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 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.

623 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