Delete files from recycle bin

Delete files from recycle bin

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


Hello

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
Gianco
 
 
 

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,
false);

IntPtr pidl;

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

SHGetPathFromIDList(pidl, buffer);

Console.WriteLine(buffer.ToString());

}

[DllImport("coredll")]

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

[DllImport("ceshell")]

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

[DllImport("ceshell")]

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;
SHGetMalloc(&pMalloc);
pMalloc->Free(pidl);
pMalloc->Release();

--
Alex Feinman
---
Visit http://www.yqcomputer.com/

 
 
 

Delete files from recycle bin

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

Many thanks Alex!

Gianco