Obtaining recycle bin folder
-
I'm trying to obtain the recycle bin folder and have tried the following two ways. Both of them dont work, any idea what is wrong in each of them? I ran them on Windows XP.
void recycle_bin1() { char szPath[4096] = { '\0' }; HRESULT hr = SHGetFolderPath(NULL, CSIDL_BITBUCKET, NULL, SHGFP_TYPE_CURRENT, szPath); const char *str = "SUCCEEDED"; if (hr == S_FALSE) { str = "S_FALSE"; } if (hr == E_FAIL) { str = "E_FAIL"; } if (hr == E_INVALIDARG) { str = "E_INVALIDARG"; } MessageBox(NULL, szPath, str, NULL); } void recycle_bin2() { char szPath[4096] = { '\0' }; BOOL bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_BITBUCKET, FALSE); const char *str = "SUCCEEDED"; if (bRet == FALSE) { str = "FAILED"; } MessageBox(NULL, szPath, str, NULL); }
thanks! -
I'm trying to obtain the recycle bin folder and have tried the following two ways. Both of them dont work, any idea what is wrong in each of them? I ran them on Windows XP.
void recycle_bin1() { char szPath[4096] = { '\0' }; HRESULT hr = SHGetFolderPath(NULL, CSIDL_BITBUCKET, NULL, SHGFP_TYPE_CURRENT, szPath); const char *str = "SUCCEEDED"; if (hr == S_FALSE) { str = "S_FALSE"; } if (hr == E_FAIL) { str = "E_FAIL"; } if (hr == E_INVALIDARG) { str = "E_INVALIDARG"; } MessageBox(NULL, szPath, str, NULL); } void recycle_bin2() { char szPath[4096] = { '\0' }; BOOL bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_BITBUCKET, FALSE); const char *str = "SUCCEEDED"; if (bRet == FALSE) { str = "FAILED"; } MessageBox(NULL, szPath, str, NULL); }
thanks!http://www.codeproject.com/shell/recyclebin.asp[^] if you need to recycle bin folder maybe it is some helpful to you
-
I'm trying to obtain the recycle bin folder and have tried the following two ways. Both of them dont work, any idea what is wrong in each of them? I ran them on Windows XP.
void recycle_bin1() { char szPath[4096] = { '\0' }; HRESULT hr = SHGetFolderPath(NULL, CSIDL_BITBUCKET, NULL, SHGFP_TYPE_CURRENT, szPath); const char *str = "SUCCEEDED"; if (hr == S_FALSE) { str = "S_FALSE"; } if (hr == E_FAIL) { str = "E_FAIL"; } if (hr == E_INVALIDARG) { str = "E_INVALIDARG"; } MessageBox(NULL, szPath, str, NULL); } void recycle_bin2() { char szPath[4096] = { '\0' }; BOOL bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_BITBUCKET, FALSE); const char *str = "SUCCEEDED"; if (bRet == FALSE) { str = "FAILED"; } MessageBox(NULL, szPath, str, NULL); }
thanks!What are the return values and last error codes after calling the APIs?
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
What are the return values and last error codes after calling the APIs?
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
The first one returns E_INVALIDARG and the second one returns FALSE. MSDN doesnt say these APIs set the last error code, so I havent printed them. I'm away from the computer that has this code, I will get back with the error codes in a couple of hours. thanks!
-
The first one returns E_INVALIDARG and the second one returns FALSE. MSDN doesnt say these APIs set the last error code, so I havent printed them. I'm away from the computer that has this code, I will get back with the error codes in a couple of hours. thanks!
Most APIs that return a
BOOL
will set the last error - otherwise there's no indication of what the error was.SHGetFolderPath()
is returningE_INVALIDARG
becauseCSIDL_BITBUCKET
isn't a constant that it supports (the docs list which ones it accepts, it's a subset of the full list).--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Most APIs that return a
BOOL
will set the last error - otherwise there's no indication of what the error was.SHGetFolderPath()
is returningE_INVALIDARG
becauseCSIDL_BITBUCKET
isn't a constant that it supports (the docs list which ones it accepts, it's a subset of the full list).--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
OK, that means I cannot use both of
SHGetFolderPath
andSHGetSpecialFolderPath
. Btw, both of these APIs returned last error 6 (invalid handle), which in some sense is meaningless. Looking at the codeproject article you gave, they useSHGetSpecialFolderLocation
which supportsCSIDL_BITBUCKET
, but it returnsLPITEMIDLIST
and I am not sure how to obtain the folder name from that. In any case, I was looking at the documentation ofCSIDL_BITBUCKET
again, and it gives me thevirtual folder
containing the items in the recycle bin. I'm not sure if COM is the only way to access the items in this virtual folder, as shown in the article, or if there is a simpler way too. So, what I really want is, the name of the recycle bin folder on each of the drives on the system, like C:\RECYCLER. Since it is C:\RECYCLED on a FAT drive, I wanted to use a windows API to obtain the correct name. So, I guessCSIDL_BITBUCKET
wont give me that - is this right? So, may be I should just enumerate the drives, get the file system type, and use RECYCLED or RECYCLER appropriately. Here is a link that talks about these folder names - http://blogs.msdn.com/oldnewthing/archive/2006/01/31/520225.aspx[^] - although it is not clear from this link what happens to a folder named RECYCLER on a FAT drive that is converted to NTFS. thanks! -
OK, that means I cannot use both of
SHGetFolderPath
andSHGetSpecialFolderPath
. Btw, both of these APIs returned last error 6 (invalid handle), which in some sense is meaningless. Looking at the codeproject article you gave, they useSHGetSpecialFolderLocation
which supportsCSIDL_BITBUCKET
, but it returnsLPITEMIDLIST
and I am not sure how to obtain the folder name from that. In any case, I was looking at the documentation ofCSIDL_BITBUCKET
again, and it gives me thevirtual folder
containing the items in the recycle bin. I'm not sure if COM is the only way to access the items in this virtual folder, as shown in the article, or if there is a simpler way too. So, what I really want is, the name of the recycle bin folder on each of the drives on the system, like C:\RECYCLER. Since it is C:\RECYCLED on a FAT drive, I wanted to use a windows API to obtain the correct name. So, I guessCSIDL_BITBUCKET
wont give me that - is this right? So, may be I should just enumerate the drives, get the file system type, and use RECYCLED or RECYCLER appropriately. Here is a link that talks about these folder names - http://blogs.msdn.com/oldnewthing/archive/2006/01/31/520225.aspx[^] - although it is not clear from this link what happens to a folder named RECYCLER on a FAT drive that is converted to NTFS. thanks!oh oh OH... that's the sound of me realizing something. I was focussing on the return values and not the folder you were looking at. The Recycle Bin isn't a file system directory, so
SHGetSpecialFolderPath()
will never work. I don't know of an API to get the name of the actual file system dir (recycled/recycler/whatever it is). If you are interested in the contents of the Bin, then useSHGetSpecialFolderLocation()
to get the PIDL to the Bin, then use the shell folder interfaces to enumerate the contents.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ