GetSpecialFolder / sfRecycleBin appears not to work

delphi package - easy access to shell apis
Post Reply
atocaciu
Posts: 3
Joined: Thu Jul 29, 2004 8:04 pm

GetSpecialFolder / sfRecycleBin appears not to work

Post by atocaciu »

Dear Madshi,

I am evaluating your madCollection, and trying to build a small program for obtaining system summary.

I saw that everyone in this forum praises your package - and I fully agree with them. I intended to do that too, but it is too common :wink: so i'll go straight to the point.

On my machine, madShell's GetSpecialFolder works fine, except for sfRecycleBin, to which it returns something like ::{645FF040-5081-101B-9F08-00AA002F954E}. I've searched through the registry and there are some keys with this name, that contain strings like 'Recycle Bin', but none of them contains any reference to the actual path for the Recycle Bin itself, so it is a dead end.

On the same machine, there are one Windows 98 SE and one Windows XP ~2600. The problem is the same on both of them. Both copies are legal and are correctly installed as far as I know.

How can I correct the problem?

Thank you,
Alan
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Hi Alan,

the problem is quite simple: madShell tells you the normal file path (like "C:\whatever") whenever one exists. If there's no file path, it returns a GUID path (like "::{...}\::{...}"). If you browse through the naming space with the explorer you'll meet a lot of objects which have no normal file path. E.g. "My Computer" doesn't have a path like "C:\whatever". You could eventually identify "My Computer" by searching for an object with the name "My Computer", but what happens if the object was renamed? So for non-file-system objects madShell uses those GUID paths. Evidently the recycle bin is such a non-file-system object. madShell asks Windows for a file path, but Windows claims there is none. As a result madShell returns the GUID path. Well, but there IS a recycle folder on each drive! Yes, there is. But (for XP at least) Windows combines all those folders from all writable drives to one object, which is the recycle bin object.

Try this: Empty the recycle bin in XP. Then delete one file from harddisk partition "C:" and one file from partition "D:". Now execute the command line "explorer.exe ::{645FF040-5081-101B-9F08-00AA002F954E}". You'll see the recycle bin and you'll see *both* files in it - although the deleted files are stored in two different recycle bin folders. Do you see the problem? Which path is Windows supposed to give you? "C:\Recycled" or "D:\Recycled"?
atocaciu
Posts: 3
Joined: Thu Jul 29, 2004 8:04 pm

Post by atocaciu »

Hi Madshi,

Thank you for your extensive answer.
I was aware of some parts of the mechanism you described (which by the way was also kind and way beyond strictly your library's domain), and your package gives a reasonable answer to my request from this point of view.

I was only asking how can i get the Recycle Bin(s) path(s) using your library.
Or, alternatively, I can benefit from a method to empty the entire Recycle Bin using your library. Is there any?

Thank you again for your support,
Alan
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, Windows refuses to give us a recycle bin path, and in the registry there's no real path, either - so my components can't give you one.

Emptying the recycle bin is quite easy, though (but doesn't work in the older OSs):

Code: Select all

procedure EmptyRecycleBin;
var SHEmptyRecycleBin : function (window: dword; root: pchar; flags: dword) : integer; stdcall;
begin
  SHEmptyRecycleBin := GetProcAddress(GetModuleHandle(shell32), 'SHEmptyRecycleBinA');
  if @SHEmptyRecycleBin <> nil then
    SHEmptyRecycleBin(0, nil, 7);
end;
atocaciu
Posts: 3
Joined: Thu Jul 29, 2004 8:04 pm

Post by atocaciu »

Madshi,

Thank you very much for your assistance and for the quick answers.

Have a nice day,
Alan
naldira
Posts: 1
Joined: Thu May 06, 2010 7:50 am

Post by naldira »

How to recover deleted data on the recycle bin after emtying it? Can I ask for some assistance on how to recover my data's after empying the recycle bin.
Last edited by naldira on Fri May 21, 2010 6:23 am, edited 1 time in total.
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I don't know how that works.
Post Reply