Can't get Recycle Bin path using SHGetKnownFolderPath

252 views Asked by At

Can't get Recycle Bin path using SHGetKnownFolderPath. Hard coding C:\\$Recycle.Bin is an option which I want to avoid. Is there a way around this issue?

static std::string GetKnownWindowsFolder(REFKNOWNFOLDERID folderId, const char* errorMsg) {
    LPWSTR wszPath = NULL;
    HRESULT hr;
    hr = SHGetKnownFolderPath(folderId, KF_FLAG_CREATE, NULL, &wszPath);
    FreeCoTaskMemory scopeBoundMemory(wszPath);

    if (!SUCCEEDED(hr)) {
        throw std::runtime_error(errorMsg);
    }
    return sago::internal::win32_utf16_to_utf8(wszPath);
}

Thank You!

Get the folder path of Recycle Bin

1

There are 1 answers

0
Anders On

The Recycle Bin is a virtual folder (like Control Panel and My Computer), it does not have a traditional path.

These virtual folders can be represented by an ITEMIDLIST. Call SHGetKnownFolderIDList() to retrieve it. See Introduction to the Shell Namespace for more information about the Shell Namespace and ItemIDLists.

That being said, there is a hidden Recycle Bin folder on each local drive, and the virtual folder displays a merged view of all of them. You can check if a folder is the Recycle Bin folder.