Re: How do I delete a folder through code?
- From: scs0 <scs0@xxxxxxx>
- Date: Wed, 7 May 2008 15:15:42 -0700 (PDT)
In that case you should try to provide the actual code you have problems with.
We're not telepathic.
I did!
Why use dangerous and inefficient memset when you can just do (assuming C++)
SHFILEOPSTRUCTW info = {};
Habit. But yours is a better way of doing this.
TCHAR szBuffer[2048];
memset(szBuffer, 0, sizeof(szBuffer));
See earlier comment about memset.
Normally I do:
TCHAR szBuffer[2048] = {_T("")};
This situation is different. Here I need to do more than create a
character array with a single leading null terminator. With this
SHFileOperation function the string field is designed to handle a
series of NULL terminated strings. The final string ends with a
double terminator. An easy way of doing this is to fill the entire
array with zeros up front and then I'm guaranteed to have a full
string.
_tcscpy(szBuffer, _T("\\\\?\\"));
I'm not sure, but I think this prefix works only for Unicode.
This folder contains a long chain of subfolders that exceeds Window's
MAX_PATH character path length. These folders cannot be deleted in
Windows Explorer due to this situation. Since "\\?\" is how you use
the API to access locations beyond this limit I've added it here.
_tcscat(szBuffer, (LPCTSTR)strFolderToDelete);This is very dangerous: you can easily exceed the buffer size.
Not here. I originally get the name of the folder from a Windows
Common Control, and since Windows has a MAX_PATH (260) character limit
I can never exceed my 2048 character limit. I admit that I
accidentally mixed TCHARs and WCHAR functions, but even then the array
cannot be exceeded.
Plus, this is a little test app. I just need to kill some directories
ASAP and don't really need anything sophisticated and entirely safe.
That's why I wasn't careful with the wide/single byte string mismatch
(multibyte is a terribly misleading name) and it's why I used ugly
hardcoded numbers. This was just a 5 minute task that turned into an
exercise in frustration due to an API that doesn't adequately support
the very basics of interaction with the filesystem (Hell, Windows
doesn't even have a notification to let you know when an flash card
volume is inserted into a reader.)
Anyway, have you checked that te resulting string makes sense as a path?
Yes.
Comes out to something like: "\\?\c:\Folder\Alpha\Whatever"
info.pFrom = szBuffer;
if (0 != SHFileOperationW(&info))
And... What's the actual code? So far you've only set up some buffers.
That's it. SHFileOperationW is the call that's supposed to delete the
folder. It's part of the Windows API. You initialize the structure
then pass it into that function. It fails and that's the bug.
Assuming this is all the code you're using to delete folder, that's the reason
it's not deleted. You need to isse some function call that deletes the folder.
For example, a call to SHFileOperation().
Um... *scratches head*
That's what I did and you questioned for the location of the actual
code.
- Alf
BTW, I loved your TV show.
.
- References:
- How do I delete a folder through code?
- From: scs0
- Re: How do I delete a folder through code?
- From: Alf P. Steinbach
- How do I delete a folder through code?
- Prev by Date: Re: How do I delete a folder through code?
- Next by Date: Re: How do I delete a folder through code?
- Previous by thread: Re: How do I delete a folder through code?
- Next by thread: Re: How do I delete a folder through code?
- Index(es):
Relevant Pages
|