VC deletes, copies, and moves folders and their files.

Source: Internet
Author: User
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

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.