Re: How do I delete a folder through code?
* Alexander Grigoriev:
"Alf P. Steinbach" <alfps@start.no> wrote in message
news:uLKdnZ7Z-rLyab_VnZ2dnUVZ_jWdnZ2d@posted.comnet...
* Alexander Grigoriev:
"scs0" <scs0@vol.com> wrote in message
news:4f5cd574-f63e-4b1e-bb77-fe10248bee00@w34g2000prm.googlegroups.com...
I cleaned up the code and found that it will work for shallow folders
but anything that has a deep subfolder structure seems to fail
// Delete the contents of the driver's backup folder
SHFILEOPSTRUCT info = {};
info.wFunc = FO_DELETE;
info.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
TCHAR szBuffer[2048] = {};
_tcscpy(szBuffer, _T("\\\\?\\"));
_tcscat(szBuffer, (LPCTSTR)strChosenFolder);
info.pFrom = szBuffer;
if (0 != SHFileOperation(&info))
pFrom should be double-zero terminated.
Unless the strChosenFolder is very long, the copy in szBuffer is
double-zero terminated.
Note that the buffer is zeroed.
Depending on VC version, empty initializer list {} may not be the same as
{0}.
I suspect that you mean something else (and incorrect) than what you're
literally stating, where the part after the comma is literally correct as a
general statement, although not in this specific case.
The standard says that for {}, each item in the aggregate is
default-initialized; in this case by TCHAR(). Until recently, IIRC, for POD,
default initialized meant non-initialized.
Default-initialization reduces to zero-initialization for PODs.
The VC problem in that respect has, as far as I know, nothing to do with curly
braces initializers, but manifests with initialization of an array member via an
initializer list, and, of course, with implementation of value initialization
(which was introduced in C++03, so obviously no earlier VC version had it).
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?