Re: SHFileOperation question
Re: SHFileOperation question
Quote:
Originally Posted by Zim327
Yes, I've already looked at it before. It is a file by file deletion. I would liek to use the shell structure to delete many files at the same time. I have problems passing the CComBSTR to it.
Re: SHFileOperation question
Unicode must be enabled
shDelete.pFrom = (LPCTSTR)pathWild.operator BSTR( );
or you could load the bstr into a TCHAR buf[255];
I got these suggestions here:
http://www.csupomona.edu/~dlbell/cpp...sfa99/174.html
the msdn states: Multiple names must be null-separated. The list of names must be double null-terminated.
so I'm not sure you can use wild cards (.*)
HTH,
Re: SHFileOperation question
wait there's more!
to use wild cards *.* you must use this flag FOF_FILESONLY
And you should be able to load the bstr into a CString and then use operator LPCTSTR. again unicode must be enabled.
Re: SHFileOperation question
Quote:
Originally Posted by Zim327
Unicode must be enabled
shDelete.pFrom = (LPCTSTR)pathWild.operator BSTR( );
or you could load the bstr into a TCHAR buf[255];
I got these suggestions here:
http://www.csupomona.edu/~dlbell/cpp...sfa99/174.html
the msdn states: Multiple names must be null-separated. The list of names must be double null-terminated.
so I'm not sure you can use wild cards (.*)
HTH,
In MSDN it says also:
Standard Microsoft MS-DOS wild cards, such as "*", are permitted in the file-name position.
I've basically tried all string conversions from CComBSTR to pass to a shell structure, but I guess the integer length of the string that is stored preceding the address of a string in CComBSTR is my problem in trying to convert it properly to hold the address of a string. Passed BSTR to the function hold an address of "0x004240a4 'string' ", when I convert CComBSTR to BSTR or LPCTSTR it holds only "0x004240a4".
Re: SHFileOperation question
Quote:
Originally Posted by Zim327
wait there's more!
to use wild cards *.* you must use this flag FOF_FILESONLY
And you should be able to load the bstr into a CString and then use operator LPCTSTR. again unicode must be enabled.
No, luck either. But thanks for the remark.
Re: SHFileOperation question
If Unicode is enabled then you won't see the contents of any of the strings in the debugger.
you must add the string to the watch window and then add ,su after it and then
you can see the contents.
have you tried hard coding the string just to see if it will work? just to make sure it's definitely a string problem?
Re: SHFileOperation question
Quote:
Originally Posted by Zim327
If Unicode is enabled then you won't see the contents of any of the strings in the debugger.
you must add the string to the watch window and then add ,su after it and then
you can see the contents.
have you tried hard coding the string just to see if it will work? just to make sure it's definitely a string problem?
Yes, I've hard coded LPCTSTR like
LPCTSTR test = L"C:\\Something\\files.*";
and it works fine with Shell Structure.
The same with BSTR:
BSTR test2 = L"C:\\Something\\files.*"
So, it is definitely some problem with string address.
Re: SHFileOperation question
Quote:
Originally Posted by tigrushke
It is a file by file deletion.
Well...what do you think happens internally while using 'SHFileOperation()'? ;)
Re: SHFileOperation question
I've solved my task with file by file deletion (checking for ReadOnly property and if it is true setting it to normal state, and then :: DeleteFile(file)), but it is not code sufficient, and I would like to simplify my code with separate Shell structure method.
So, I am still looking for solution on this problem.
Re: SHFileOperation question
Quote:
Originally Posted by Andreas Masur
Well...what do you think happens internally while using 'SHFileOperation()'? ;)
I bet it is definitely file by file deletion :) I would be happy to debug Shell structure code to understand in full where it fails, but unfortunatelly, I cannot do that.
Re: SHFileOperation question
The folowing code deletes all files inside D:\tempDir\folder1
Code:
CString tempDir = L"D:\\tempDir\\folder1\\*";
ASSERT(tempDir.GetLength()+2 > MAX_PATH);
TCHAR path[MAX_PATH];
wcscpy_s(path, MAX_PATH, tempDir.GetBuffer());
path[tempDir.GetLength()] = '\0';
path[tempDir.GetLength()+1] = '\0';
SHFILEOPSTRUCT fileOP;
ZeroMemory(&fileOP, sizeof(SHFILEOPSTRUCT));
fileOP.hwnd = NULL;
fileOP.wFunc = FO_DELETE;
fileOP.pFrom = path;
fileOP.pTo = NULL;
fileOP.fFlags = FOF_NO_UI;
BOOL bRes = SHFileOperation(&fileOP);
ASSERT(!bRes);
what I have tried to stress upon is how important it really is to put two NULLs at the end of string. I was getting the 1026 error for a long time till I really made sure it is double NULL terminated.
Happy debugging! (and sorry for writing in a very old thread. blame google for that. i m innocent, my lord.)