/// <summary> /// Empties the Recycle Bin. /// </summary> /// <param name="window">The owner window</param> /// <param name="drivePath">The path to the Recycle Bin drive. Leave this parameter null or empty if you want to get the info for the Recycle Bins for all drives.</param> /// <param name="emptyRecycleBinFlags">Flags to describe the behavior for the process.</param> /// <returns><see langword="true"/> if the drive supports the Recycle Bin, otherwise <see langword="false"/>.</returns> /// <exception cref="Win32Exception">Exception thrown if a Win32 exception has occurred during thr process.</exception> public static bool EmptyRecycleBin(Window window, string drivePath, EmptyRecycleBinFlags emptyRecycleBinFlags) { HResult hr = SHEmptyRecycleBin(new WindowInteropHelper(window).Handle, drivePath, emptyRecycleBinFlags); if (hr == HResult.Ok) { return(true); } else if (hr == HResult.Fail) { return(false); } else { Marshal.ThrowExceptionForHR((int)hr); } return(false); }
public static extern HResult SHEmptyRecycleBin(IntPtr hWnd, string pszRootPath, EmptyRecycleBinFlags dwFlags);