Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Obtaining recycle bin folder

Obtaining recycle bin folder

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chintoo723
    wrote on last edited by
    #1

    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!

    H M 2 Replies Last reply
    0
    • C Chintoo723

      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!

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      http://www.codeproject.com/shell/recyclebin.asp[^] if you need to recycle bin folder maybe it is some helpful to you

      1 Reply Last reply
      0
      • C Chintoo723

        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!

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • M Michael Dunn

          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

          C Offline
          C Offline
          Chintoo723
          wrote on last edited by
          #4

          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!

          M 1 Reply Last reply
          0
          • C Chintoo723

            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!

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Most APIs that return a BOOL will set the last error - otherwise there's no indication of what the error was. SHGetFolderPath() is returning E_INVALIDARG because CSIDL_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

            C 1 Reply Last reply
            0
            • M Michael Dunn

              Most APIs that return a BOOL will set the last error - otherwise there's no indication of what the error was. SHGetFolderPath() is returning E_INVALIDARG because CSIDL_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

              C Offline
              C Offline
              Chintoo723
              wrote on last edited by
              #6

              OK, that means I cannot use both of SHGetFolderPath and SHGetSpecialFolderPath. 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 use SHGetSpecialFolderLocation which supports CSIDL_BITBUCKET, but it returns LPITEMIDLIST and I am not sure how to obtain the folder name from that. In any case, I was looking at the documentation of CSIDL_BITBUCKET again, and it gives me the virtual 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 guess CSIDL_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!

              M 1 Reply Last reply
              0
              • C Chintoo723

                OK, that means I cannot use both of SHGetFolderPath and SHGetSpecialFolderPath. 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 use SHGetSpecialFolderLocation which supports CSIDL_BITBUCKET, but it returns LPITEMIDLIST and I am not sure how to obtain the folder name from that. In any case, I was looking at the documentation of CSIDL_BITBUCKET again, and it gives me the virtual 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 guess CSIDL_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!

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                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 use SHGetSpecialFolderLocation() 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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups