我跟随this article,其中显示了如何判断特定文件夹是否为回收站。这是我自己的版本:
LPITEMIDLIST pidl = NULL;
if (SUCCEEDED(hr = SHParseDisplayName(pFolderPath, NULL, &pidl, 0, NULL)))
{
IShellFolder *psf = NULL;
LPCITEMIDLIST pidlChild;
if (SUCCEEDED(hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&psf, &pidlChild)))
{
SHDESCRIPTIONID did = {0};
if(SUCCEEDED(hr = SHGetDataFromIDList(psf, pidlChild, SHGDFIL_DESCRIPTIONID, &did, sizeof(did))))
{
if(did.clsid == CLSID_RecycleBin)
{
_tprintf(L"Folder is the Recycle Bin!\n");
}
}
psf->Release();
}
}
if(pidl)
{
CoTaskMemFree(pidl);
pidl = NULL;
}
该代码适用于本地回收站,但如果是重定向到网络共享的文件夹(例如,我的文档)的回收站,则服务器上的路径将变为如下所示:{{1}上面的方法不起作用,即\\SRVR-A\Home\UserName\Documents\$RECYCLE.BIN
为0,did.clsid
为did.dwDescriptionId
,就像常规文件夹一样。