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; } } |