Delete files from recycle bin

Delete files from recycle bin

Post by gianfranco » Tue, 15 Feb 2005 20:02:36


Is there a function to delete all files from the recycle bin or, which
is the path to access to the recycle bin?

Thanks in advance

Delete files from recycle bin

Post by Alex Feinm » Wed, 16 Feb 2005 07:48:59

Path to Recycle Bin can be obtained by PInvoking SHGetSpecialFolderLocation:
static void Main(string[] args)


const int CSIDL_BITBUCKET = 0x000a;

StringBuilder buffer = new StringBuilder(256);

int ret = SHGetSpecialFolderPath(IntPtr.Zero, buffer, CSIDL_BITBUCKET,

IntPtr pidl;

SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL_BITBUCKET, out pidl);

SHGetPathFromIDList(pidl, buffer);




extern static int SHGetSpecialFolderPath(IntPtr hWnd, StringBuilder buffer,
int Folder, bool Create);


extern static int SHGetSpecialFolderLocation(IntPtr hWnd, int Folder, out
IntPtr pidl);


extern static int SHGetPathFromIDList( IntPtr pidl, StringBuilder pszPath );

A bit of problem with this code is that it does not free memory allocated to
pidl. If you are going to call this once or twice over your app lifetime,
it's not a big deal. If however you are going to keep calling this, you will
need to do this properly in unmanaged code:

IMalloc pMalloc;

Alex Feinman


Delete files from recycle bin

Post by gianfranco » Wed, 16 Feb 2005 19:15:30

Many thanks Alex!