Re: How do I delete a folder through code?
* scs0:
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))
I'm unable to reproduce the problem with the code I posted.
<console>
V:\test> md bah\c\d\e\f\g\h\i\j\k\l
V:\test> dir /b bah
c
V:\test> x
V:\test> dir /b bah
File Not Found
V:\test> _
</console>
I won't try with your code because the effect depends on the compiler options
(all that "_T" stuff), so could well be different from what you do, and so
testing wouldn't tell anything. But there's one possible cause other than that
your code can fail if it doesn't get the required compiler options. Namely,
"\\?\" indicates that you're dealing with very long paths, but Explorer, and
hence presumably also the shell functions, is/are limited to MAX_PATH.
It's a good idea to write code that depends as little as possible on compiler
options, and it's a bad idea to write code that for no good reason requires
various compiler options.
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?