Copy an MFC File

Source: Internet
Author: User

Copy an MFC File

Functions used:

Bool copyfile (maid, maid );

The lptstr lpexistingfilename already exists, for example, D: // 123.prt.

New name of the lpnewfilename copied by the lptstr, such as: D: // program file // 123.prt

Bool bfailifexists: Specifies whether to overwrite a new file name if it already exists. True: Do not overwrite false: Overwrite

 

Void filecopyto (cstring source, cstring destination, cstring searchstr, bool cover)
{
Cstring strsourcepath = source;
Cstring strdespath = destination;
Cstring strfilename = searchstr;
Cfilefind filefinder;
Cstring strsearchpath = strsourcepath + "//" + strfilename;
Cstring filename;
Bool bfind = filefinder. findfile (strsearchpath );

Cstring sourcepath, dispath;
While (bfind)
{
Bfind = filefinder. findnextfile ();
Filename = filefinder. getfilename ();
Sourcepath = strsourcepath + "//" + filename;
Dispath = strdespath + "//" + filename;
Copyfile (lpcstr) sourcepath, (lpcstr) dispath, true );
}
Filefinder. Close ();
}

Void main ()
{
Char * sor = "E: // fox_work // model //";
Char * des = "E: // fox_work //";
Char * filename = "liangan. PRT ";
Filecopyto (SOR, Des, filename, true );
}

In this way, copy the liangan. PRT file under the E:/fox_work/model/directory to the E:/fox_work/directory.

 

Yes

Bool copyfileex (maid, maid, DWORD dwflag)
{
Shfileopstruct lpfileop;
Lpfileop. hwnd = afxgetmainwnd ()-> getsafehwnd ();
Lpfileop. wfunc = fo_copy;
Lpfileop. pfrom = lpszsrc;
Lpfileop. PTO = lpszdec;
Lpfileop. fflags = dwflag;
Lpfileop. fanyoperationsaborted = false;
Lpfileop. hnamemappings = NULL;
Lpfileop. lpszprogresstitle = NULL;
Int rval = shfileoperation (& lpfileop );
Cstring strmsg;
If (rval = 0)
{

If (lpfileop. fanyoperationsaborted = true)
{
Strmsg = "copying files ";
Strmsg + = lpszsrc;
Strmsg + = "Operation canceled! ";
: Afxmessagebox (strmsg, mb_ OK );
Return false;
}
Else
{
: Afxmessagebox ("file copy operation successful! ", Mb_ OK );
Return true;
}
}
Else
{
Strmsg = "copying files from ";
Strmsg + = lpszsrc;
Strmsg + = "";
Strmsg + = lpszdec;
Strmsg + = "failed! ";
: Afxmessagebox (strmsg, mb_ OK | mb_iconexclamation );
Return false;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.