none
How do I clean out the Recycle Bin?

Answers

  • Matt,
    you can also call the SHEmptyRecycleBin API, that will allow you to select which recycle bins you want to clear, will provide a confirmation prompt, a sound, and the progress dialog (all of which options can be disabled).

    A rough signature for the API would be:

    [DllImport("shell32.dll")]
    public static extern IntPtr SHEmptyRecycleBin(IntPtr hwnd, [MarshalAs(UnmanagedType.LPTStr)] string path, uint dwflags);

    you may also need to declare the constants (from shellapi.h), if you want to customize the behaviour:
    public const uint SHERB_NOCONFIRMATION = 0x00000001;
    public const uint SHERB_NOPROGRESSUI = 0x00000002;
    public const uint SHERB_NOSOUND = 0x00000004;

    Then you can call the API. You can use IntPtr.Zero for hwnd, null for the path, 0  for dwflags. This will give you the default behaviour.

    SHEmptyRecycleBin(IntPtr.Zero, null, 0);

    Read the documentation on this API on the msdn, then play with the parameters as you see fit.
    HTH
    --mc

    Sunday, May 28, 2006 10:57 PM

All replies

  • LoL

    just delete the file from it..

    you can use File class or Directory
    Sunday, May 28, 2006 8:32 PM
  • Matt,
    you can also call the SHEmptyRecycleBin API, that will allow you to select which recycle bins you want to clear, will provide a confirmation prompt, a sound, and the progress dialog (all of which options can be disabled).

    A rough signature for the API would be:

    [DllImport("shell32.dll")]
    public static extern IntPtr SHEmptyRecycleBin(IntPtr hwnd, [MarshalAs(UnmanagedType.LPTStr)] string path, uint dwflags);

    you may also need to declare the constants (from shellapi.h), if you want to customize the behaviour:
    public const uint SHERB_NOCONFIRMATION = 0x00000001;
    public const uint SHERB_NOPROGRESSUI = 0x00000002;
    public const uint SHERB_NOSOUND = 0x00000004;

    Then you can call the API. You can use IntPtr.Zero for hwnd, null for the path, 0  for dwflags. This will give you the default behaviour.

    SHEmptyRecycleBin(IntPtr.Zero, null, 0);

    Read the documentation on this API on the msdn, then play with the parameters as you see fit.
    HTH
    --mc

    Sunday, May 28, 2006 10:57 PM
  • While you *can* clean out the Recycle Bin using the API, the question arises about whether or not you *should* clean it out. 

    If this is on your own machine, then fine, but if your program is to be run on other people's machine and you clean their Recycle Bin, especially without their knowledge, they might get very upset.

    Exercise caution!


    Tuesday, May 30, 2006 9:08 PM