Solved

Copy and Delete

Posted on 2002-06-21
4
221 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
Comment Utility
delete should be:
int _unlink( const char *filename );
0
 
LVL 30

Accepted Solution

by:
Axter earned 50 total points
Comment Utility
You can use CopyFile() API function

For delete you can use DeleteFile() API function

0
 
LVL 30

Expert Comment

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

Expert Comment

by:jhance
Comment Utility
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

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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.

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now