Delete:
Void coperationdlg: ondel2 (cstring m_strfiledic.pdf) // The parameter is the directory path.
{
If (m_strfiledictory.getlength () = 0)
{
: Afxmessagebox ("the directory name is invalid !", Mb_ OK | mb_iconexclamation );
Return;
}
Char fromfilename [80] = "/0 ″;
Strcpy (fromfilename, m_strfiledic.pdf );
Strcat (fromfilename, "/0 ″);
Shfileopstruct lpfileop;
Lpfileop. hwnd = getsafehwnd ();
Lpfileop. wfunc = fo_delete;
Lpfileop. pfrom = fromfilename;
Lpfileop. PTO = NULL;
Lpfileop. fflags = fof_silent | fof_noconfirmation;
Lpfileop. fanyoperationsaborted = false;
Lpfileop. hnamemappings = NULL;
Lpfileop. lpszprogresstitle = NULL;
Int rval = shfileoperation (& lpfileop );
If (rval = 0)
{
If (lpfileop. fanyoperationsaborted = true)
: Afxmessagebox ("Delete directory operation canceled", mb_ OK );
Else
: Afxmessagebox ("directory deletion successful !", Mb_ OK | mb_iconexclamation );
}
Else
{
: Afxmessagebox ("failed to delete directory operation !", Mb_ OK | mb_iconexclamation );
}
}
Copy
Bool ccutfolddlg: copydirectory (cstring sourcepath, cstring copytopath)
{
Cfilefind tempfind;
Char tempfilefind [200];
Char tempfilefind1 [200];
Security_attributes lpsecuritydescriptor;
Createdirectory (copytopath, & lpsecuritydescriptor );
/*{
If (: MessageBox (0, "the file already exists. Do you want to overwrite it ?"," Warning ", mb_iconquestion | mb_yesno) = IDNO)
Return false;
}
*/
Sprintf (tempfilefind1, "% S // *. *", copytopath );
Sprintf (tempfilefind, "% S // *. *", sourcepath );
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
// BOOL IsFinded1=(BOOL)tempFind.FindFile(tempFileFind1);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200];
// char foundFileName1[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
// strcpy(foundFileName1,tempFind.GetFileName().GetBuffer(200));
if(tempFind.IsDirectory())
{
char tempDir[200];
char tempDir1[200];
sprintf(tempDir,”%s//%s”,SourcePath,foundFileName);
sprintf(tempDir1,”%s//%s”,CopytoPath,foundFileName);
CopyDirectory(tempDir,tempDir1);
}
else
{
char tempFileName[200];
char tempFileName1[200];
sprintf(tempFileName,”%s//%s”,SourcePath,foundFileName);
sprintf(tempFileName1,”%s//%s”,CopytoPath,foundFileName);
//DeleteFile(tempFileName);
CopyFile(tempFileName,tempFileName1,0);
}
}
}
tempFind.Close();
return TRUE;
}
Mobile
To move the file, traverse the file + movefile + createdirectory
For the Traversal method, refer:
Handle hfind;
Win32_find_data datafind;
Bool bmorefiles = true;
Hfind = findfirstfile (Spath + "// *. txt", & datafind); // Spath indicates the path
While (hfind! = Invalid_handle_value & bmorefiles = true)
{
If (datafind. dwfileattributes = file_attribute_archive)
{
MessageBox (datafind. cfilename );
}
Bmorefiles = findnextfile (hfind, & datafind );
}
Findclose (hfind );
Reprint please explain the source: http://blog.csdn.net/mycaibo