7

I use this procedure:

function MoveToRecycle(sFileName: widestring): Boolean;
var
  fos: TSHFileOpStructW;
begin
  FillChar(fos, SizeOf(fos), 0);
  with fos do
  begin
    wnd := 0;
    wFunc  := FO_DELETE;
    pFrom  := PWideChar(sFileName + #0 + #0);
    pTo := #0 + #0;
    fFlags := FOF_FILESONLY or FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_SILENT;
  end;
  Result := (ShFileOperationW(fos) = 0);
end;

What will happen if the recycle bin is full, does it return false or delete file permanently ?

Any help would be appreciated.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Irwan
  • 783
  • 1
  • 13
  • 28
  • Indent your code by four spaces to get it to show up correctly. – Anon. Dec 16 '09 at 02:40
  • I wasn't aware that the Recycle Bin can be "full". How does that work? – Mason Wheeler Dec 16 '09 at 04:29
  • By the way - nice function. Actually good to know how to move to the recycle bin. I always just used "deletefile" function. – M Schenkel Dec 16 '09 at 04:35
  • Mason - you can set the recycle bin to be a "percentage" of your disk drive space. But we I learned, using this function at least, it never fills up, but instead pushes out the oldest deleted files when there is no more free capacity left. – M Schenkel Dec 16 '09 at 04:37
  • By the way, you are triple null-terminating the path. You've got one more null than you need. – David Heffernan Nov 13 '13 at 17:45

1 Answers1

3

The best way to find out is to actually do it. Made my recycle bin be minimum 1 percent of drive. Created a bunch of large files and used your function to move them to recycle bin.

What I am finding out (on XP anyways) is that the function always moves it to the recycle bin; but deletes permanently the oldest deleted file. So it appears when the recycle bin fills up it employs a "first in - first out" type approach to decide which file to boot out.

I was not able to get the function to return false. Perhaps creating a file too large for the allocated recycle bin do this.

M Schenkel
  • 6,294
  • 12
  • 62
  • 107