Solved

Copy and Delete

Posted on 2002-06-21
4
225 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
C++ question 3 84
sorting efficency of sorting algorithm 30 151
FMX TEdit KeyUp handler detecting  "enter" key 4 64
what type of pointer is this pointer? 3 32
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

752 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