Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 249441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:25:39+00:00 2026-05-11T21:25:39+00:00

I’m trying to write some simple code that will return the directory for the

  • 0

I’m trying to write some simple code that will return the directory for the recycle bin on a local drive. Seems like it would be simple — should be a thousand answers on Google. Haven’t found one yet 🙁

I HAVE found that FAT and NTFS drives have different base names (RECYCLED and RECYCLER). I’ve found that ‘the’ recycle bin is a virtual folder that combines the recycle bins of all drives on the machine.

What I haven’t found is a way to find C: drive’s recycle bin directory — even on a Vietnamese (or any other non-English) machine. (No posts I can find indicate whether “RECYCLER” gets internationalized or not)

Can anyone point me to a definitive answer?

Thanks

UPDATE: Aware of CSIDL_BITBUCKET and the functions that use it. From everything I’ve read though, it points to a virtual directory which is the union of all deleted files by that user on all drives. Looking for the physical recycle bin directory (on my Vista it appears to be C:\$Recycle.Bin as far as I can tell)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:25:39+00:00Added an answer on May 11, 2026 at 9:25 pm

    Using Raymond Chen’s advice, and someone else’s technique (can’t remember where I found it) I present a function that will find the Recycle Bin directory on a drive. The function cycles through the directories in the root directory looking at hidden and/or system directories. When it finds one, it checks the child subdirectories looking for one that has CLSID_Recycle Bin.

    Note that I’ve included two GetFolderCLSID functions below. Raymond Chen’s is the simpler one, but it doesn’t work on Windows 2000. The other implementation is longer, but appears to work everywhere.

    Call like: CString recycleDir = FindRecycleBinOnDrive(L”C:\”);

    CString FindRecycleBinOnDrive(LPCWSTR path)
    {
        CString search;
        search.Format(L"%c:\\*", path[0]);
        WIN32_FIND_DATA fd = {0};
        HANDLE fHandle = FindFirstFile(search, &fd);
        while(INVALID_HANDLE_VALUE != fHandle)
        {
            if(FILE_ATTRIBUTE_DIRECTORY == (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) //only check directories
            {
                if(0 != (fd.dwFileAttributes & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) //only check hidden and/or system directories
                {
                    //the recycle bin directory itself won't be marked, but a SID-specific child directory will, so now look at them
                    CString childSearch;
                    childSearch.Format(L"%c:\\%s\\*", path[0], fd.cFileName);
                    WIN32_FIND_DATA childFD = {0};
                    HANDLE childHandle = FindFirstFile(childSearch, &childFD);
                    while(INVALID_HANDLE_VALUE != childHandle)
                    {
                        if((FILE_ATTRIBUTE_DIRECTORY == (childFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) && //only check directories
                            (childFD.cFileName[0] != L'.')) //don't check . and .. dirs
                        {
                            CString fullPath;
                            fullPath.Format(L"%c:\\%s\\%s", path[0], fd.cFileName, childFD.cFileName);
                            CLSID id = {0};
                            HRESULT hr = GetFolderCLSID(fullPath, id);
                            if(SUCCEEDED(hr))
                            {
                                if(IsEqualGUID(CLSID_RecycleBin, id))
                                {
                                    FindClose(childHandle);
                                    FindClose(fHandle);
                                    //return the parent (recycle bin) directory
                                    fullPath.Format(L"%c:\\%s", path[0], fd.cFileName);
                                    return fullPath;
                                }
                            }
                            else
                            {
                                Log(logERROR, L"GetFolderCLSID returned %08X for %s", hr, fullPath);
                            }
                        }
    
                        if(FALSE == FindNextFile(childHandle, &childFD))
                        {
                            FindClose(childHandle);
                            childHandle = INVALID_HANDLE_VALUE;
                        }
                    }
                }
            }
            if(FALSE == FindNextFile(fHandle, &fd))
            {
                FindClose(fHandle);
                fHandle = INVALID_HANDLE_VALUE;
            }
        }
        _ASSERT(0);
        return L"";
    }
    
    
    //Works on Windows 2000, and even as Local System account
    HRESULT GetFolderCLSID(LPCWSTR path, CLSID& pathCLSID)
    {
        LPMALLOC pMalloc = NULL;
        HRESULT hr = 0;
        if (SUCCEEDED(hr = SHGetMalloc(&pMalloc))) 
        {
            LPSHELLFOLDER pshfDesktop = NULL;
            if (SUCCEEDED(hr = SHGetDesktopFolder(&pshfDesktop))) 
            {
                LPITEMIDLIST pidl = NULL;
                DWORD dwAttributes = SFGAO_FOLDER;
                if (SUCCEEDED(hr = pshfDesktop->ParseDisplayName(NULL, NULL, (LPWSTR)path, NULL, &pidl, &dwAttributes))) 
                {
                    LPPERSIST pPersist = NULL;
                    if (SUCCEEDED(hr = pshfDesktop->BindToObject(pidl, NULL, IID_IPersist, (LPVOID *) &pPersist))) 
                    {
                        hr = pPersist->GetClassID(&pathCLSID); 
                        pPersist->Release();
                    } 
                    pMalloc->Free(pidl);
                } 
                pshfDesktop->Release();
            } 
            pMalloc->Release();
        }
        return hr;
    }
    
    
    //Not supported on Windows 2000 since SHParseDisplayName wasn't implemented then
    //HRESULT GetFolderCLSID(LPCWSTR pszPath, CLSID& pathCLSID)
    //{
    //  SHDESCRIPTIONID did = {0};
    //  HRESULT hr = 0;
    //  LPITEMIDLIST pidl = NULL;
    //  if (SUCCEEDED(hr = SHParseDisplayName(pszPath, NULL, &pidl, 0, NULL))) //not supported by Windows 2000
    //  {
    //      IShellFolder *psf = NULL;
    //      LPCITEMIDLIST pidlChild = NULL;
    //      if (SUCCEEDED(hr = SHBindToParent(pidl, IID_IShellFolder, (void**)&psf, &pidlChild))) 
    //      {
    //          hr = SHGetDataFromIDList(psf, pidlChild, SHGDFIL_DESCRIPTIONID, &did, sizeof(did));
    //          psf->Release();
    //          pathCLSID = did.clsid;
    //      }
    //      CoTaskMemFree(pidl);
    //  }
    //  return hr;
    //}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 226k
  • Answers 226k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We're using the maven gwt plugin to build our multi-module… May 13, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer You could add Commands to your usercontrol class and have… May 13, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer This tutorial should help you out. See 5a: http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/ http://www.webdesignerwall.com/demo/jquery/animated-hover1.html May 13, 2026 at 1:06 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.