SHGetSpecialFolderPath
with CSIDL_BITBUCKET
, but this does not work because the Recycle Bin is a virtual directory that is a combination of SHGetSpecialFolderPath
CSIDL_BITBUCKET
from all disks.RECYLCED
and RECYCLER
- a good solution, since these names depend on a lot. I already wrote that it depends on the file system . It also depends on whether the disk is accessed locally or remotely: the basket accessible via the network is called differently. This may depend on the operating system that is installed on the user. No, it’s a bad idea to prescribe the folder names for the recycle bin in the program.SHDESCRIPTIONID
structure reports a bit more about the shell folder. In addition to the “description ID”, it also gives the CLSID
, and this is what is important in this case.#include <windows.h>
#include <shlobj.h>
#include <tchar.h>
#include <stdio.h>
HRESULT
GetFolderDescriptionId(LPCWSTR pszPath, SHDESCRIPTIONID *pdid)
{
HRESULT hr;
LPITEMIDLIST pidl;
if (SUCCEEDED(hr = SHParseDisplayName(pszPath, NULL,
&pidl, 0, NULL))) {
IShellFolder *psf;
LPCITEMIDLIST pidlChild;
if (SUCCEEDED(hr = SHBindToParent(pidl, IID_IShellFolder,
(void**)&psf, &pidlChild))) {
hr = SHGetDataFromIDList(psf, pidlChild,
SHGDFIL_DESCRIPTIONID, pdid, sizeof(*pdid));
psf->Release();
}
CoTaskMemFree(pidl);
}
return hr;
}
int __cdecl wmain(int argc, WCHAR **argv)
{
SHDESCRIPTIONID did;
if (SUCCEEDED(GetFolderDescriptionId(argv[1], &did)) &&
did.clsid == CLSID_RecycleBin) {
printf("is a recycle bin\n");
} else {
printf("is not a recycle bin\n");
}
return 0;
}
GetFolderDescriptionId
function takes the path to the folder and turns it into ITEMIDLIST
to call SHGetDataFromIDList
and get the SHDESCRIPTIONID
. All we care about is whether CLSID
is Baskets or not.C:\> checkrecycle C:\Windows
is not a recycle bin
C:\> checkrecycle C:\RECYCLER\S-1-5-21-2127521184-1604012920-1887927527-72713
is a recycle bin
Source: https://habr.com/ru/post/41123/
All Articles