apidelphi

Need Recycle Bin Folder Name


I need to know the recycle Bin Folder name so that I can empty it thru my Delphi Seattle application. I have used below code without any success. Same code works for other Folders like CSIDL_COOKIES , CSIDL_RECENT etc. but somehow CSIDL_BITBUCKET does not give any output.

function GetWinSysFolders(FolderTpye:Integer):String;
var
  Allocator: IMalloc;
  SpecialDir: PItemIdList;
  FBuf: array[0..MAX_PATH] of Char;
  PerDir: string;
begin
  if SHGetMalloc(Allocator) = NOERROR then
  begin    // form1.Handle      v
    SHGetSpecialFolderLocation( 0, FolderTpye, SpecialDir);
    SHGetPathFromIDList(SpecialDir, @FBuf[0]);
    Allocator.Free(SpecialDir);
    result:=string(FBuf);
  end;
end;

Solution

  • You are not able to get a filesystem path for CSIDL_BITBUCKET because it simply does not have a single filesystem path to begin with - the "Recycle Bin" as you think of it is actually a virtual folder in the Shell. Every drive has its own physical bin storage, and CSIDL_BITBUCKET represents the virtual folder that encompasses all of the individual drive bins as a single entity in the Shell.

    Also, the "Recycle Bin" contains metadata about each deleted file, such as which user it belongs to, where it was deleted from, etc. As such, you can't interact with the contents of CSIDL_BITBUCKET at the filesystem level (not without corrupting it, anyway). You need to use the Shell interfaces instead. See Raymond Chen's blog articles on How can I get information about the items in the Recycle Bin? and Invoking commands on items in the Recycle Bin for more details. For instance, you can use the Shell interfaces to enumerate the files in the "Recycle Bin" and invoke the "delete" verb on each desired file as needed.

    That being said, the Win32 API has a simple SHEmptyRecycleBin() function to empty files from a specified drive's bin. Use that function instead of emptying the "Recycle Bin" manually.