Solved

Copy and Delete

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

749 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