Copy a folder and delete a folder

Source: Internet
Author: User
Shfileoperation Delete and copy files (CLIPS)

BOOL
DeleteFolder(
LPCTSTR lpszPath)

{

  SHFILEOPSTRUCT FileOp;

  ZeroMemory(
(
void
*
)
&
FileOp,
sizeof
(
SHFILEOPSTRUCT)
)
;

  FileOp.
fFlags =
FOF_NOCONFIRMATION;

  FileOp.
hNameMappings =
NULL
;

  FileOp.
hwnd =
NULL
;

  FileOp.
lpszProgressTitle =
NULL
;

  FileOp.
pFrom =
lpszPath;

  FileOp.
pTo =
NULL
;

  FileOp.
wFunc =
FO_DELETE;

Return
Shfileoperation (
&
Fileop)
=
=
0;

} // This function can delete directories (subdirectories and files under Directories)


This is a piece of code found online, but when deleting a directory, it is always said that the source file or disk cannot be read. But the directory does exist.

I checked msdn and found the same problem on the Internet. Let's look at their answers. In the original shfileoperation, pfrom can represent multiple paths separated by '/0' and ended with'/123456' (that is, two consecutive '/0,

So I changed it. But it still does not work.

Remove the last '/' ("C: // data //" to "C: // data") in the path.

The following functions need to pay attention to the same problem.

Bool
Copyfolder (
Lpctstr lpszfrompath,
Lpctstr lpsztopath)

{

Shfileopstruct fileop;

Zeromemory (
(
Void
*
)
&
Fileop,
Sizeof
(
Shfileopstruct)
)
;


Fileop.
Fflags =
Fof_noconfirmation;

Fileop.
Hnamemappings =
Null
;

Fileop.
Hwnd =
Null
;

Fileop.
Lpszprogresstitle =
Null
;

Fileop.
Pfrom =
Lpszfrompath;

Fileop.
PTO =
Lpsztopath;

Fileop.
Wfunc =
Fo_copy;


Return
Shfileoperation (
&
Fileop)
=
=
0;

} // Lpszfrompath indicates that the source folder lpsztopath is the destination directory. The function will create a new folder (with the same name as the source folder) in the lpsztopath folder ),


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.