Why doesn't SHGetSpecialFolderLocation work for "Recycle Bin"?

F

Frank Meng

Hi.
I wrote a program to get the directory of "Recycle Bin" with
SHGetSpecialFolderLocation .
It works for "Recent", "SendTo", etc. but it doesn't work for "Recycle
Bin".
At http://www.dot.net.nz/codesamples.browseforfolder.aspx , and other
places,
the folder Ids are:
///
/// Enum of CSIDLs identifying standard shell folders.
///
public enum FolderID
{
Desktop = 0x0000,
Printers = 0x0004,
MyDocuments = 0x0005,
Favorites = 0x0006,
Recent = 0x0008,
SendTo = 0x0009,
StartMenu = 0x000b,
MyComputer = 0x0011,
NetworkNeighborhood = 0x0012,
Templates = 0x0015,
MyPictures = 0x0027,
NetAndDialUpConnections = 0x0031,
}
0x000a (which stands for "Recycle Bin") is not even in the list !!
Does that mean SHGetSpecialFolderLocation won't work for "Recycle
Bin"?
Is that because it is a virtual folder?
Then how can I get the location of "Recycle Bin"?
Thanks for your help in advance.
Frank
PS: I posted my codes below:
//////////////////
[DllImport ( "Shell32.DLL" )]
static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner,
int nFolder, out IntPtr ppidl);
[DllImport ( "Shell32.DLL" )]
public static extern Int32 SHGetPathFromIDList(
IntPtr pidl, // Address of an item identifier list that
StringBuilder pszPath);
[STAThread]
static void Main(string[] args)
{
IntPtr pidl = IntPtr.Zero;
int CSIDL_BITBUCKET = 10; // Recycle Bin - virtual folder
// int CSIDL_BITBUCKET = 9; // SendTo Works !!
string TempString;
if( 0 == SHGetSpecialFolderLocation( (System.IntPtr)null,
CSIDL_BITBUCKET, out pidl ) )
{
// Then retrieve the path from the IDList.
StringBuilder sb = new StringBuilder ( 1000 );
SHGetPathFromIDList( pidl, sb );
TempString=sb.ToString();
}
}
 
M

Mattias Sjögren

Frank,
0x000a (which stands for "Recycle Bin") is not even in the list !!
Does that mean SHGetSpecialFolderLocation won't work for "Recycle
Bin"?

No, it just means whoever wrote that code didn't bother to include
that value in the enum. :)

SHGetSpecialFolderLocation works, but SHGetPathFromIDList doesn't.

Is that because it is a virtual folder?
Yes.


Then how can I get the location of "Recycle Bin"?

I don't think there's any API for that. Keep in mind that the Recycle
bin doesn't have a single backing file system directory, but actually
one per hard drive partition. The virtual folder is a combination of
all of them.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top