Method for deleting and copying directory in Windows

xiaoxiao2021-03-06  40

I. Delete a directory (delete all files and subdirectories in this directory) Bool crobotmatchdlg :: deletedIRectory (lpcstr szdirname) {cfilefind tempfind; char TempFileFind [200]; sprintf (TempFileFind, "% s //*.*", szdirname ); BOOL IsFinded = (BOOL) tempFind.FindFile (tempFileFind); while (IsFinded) {IsFinded = (BOOL) tempFind.FindNextFile (); if (tempFind.IsDots (!)) {char foundFileName [200]; strcpy (foundFileName , TempFind.GetFileName (). getBuffer (200)); if (TempFind.Indirectory ()) {char Tempdir [200]; Sprintf (Tempdir, "% S / /% S", SZDIRNAME, FOUNDFILENAME); DELETEDIRECTORY (TEMPDIR) ;} else {char tempFileName [200]; sprintf (tempFileName, "% s //% s", szDirName, foundFileName); DeleteFile (tempFileName);}}} tempFind.Close (); if (! RemoveDirectory (szDirName)) {MessageBox ("Delete Directory Failed!", "Warning Information", MB_OK; Return False;} Return True;

II. Copying Bool CrobotmatchDlg :: CopyDirectory (LPCSTR LPSTRSOURCE, LPCSTR LPSTRDEST) {char startle [] = "file copying";

// Set the File Operation Attribution SHFILEOPSTRUCT FileOp; FileOp.hwnd = m_hWnd; FileOp.wFunc = FO_COPY; char szBufSource [MAX_PATH] = ""; strcpy (szBufSource, lpstrSource); szBufSource [strlen (lpstrSource) 1] = 0; char szBufDest [MAX_PATH] = ""; strcpy (szBufDest, lpstrDest); szBufDest [strlen (lpstrDest) 1] = 0; FileOp.pFrom = szBufSource; FileOp.pTo = szBufDest; FileOp.fFlags = FOF_ALLOWUNDO; // FOF_NOCONFIRMATION FileOp .hnamemappings = null; fileop.lpszprogresstitle = startle;

转载请注明原文地址:https://www.9cbs.com/read-65908.html

New Post(0)