• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

emptying recycle bin

Is there an api used that can empty the recycle bin?
If I have to recursively read through it to remove all the files and folders, is the recycle bin always located at
c:\recycled?  (or whatever drive windows is installed on).
0
jexd99
Asked:
jexd99
  • 8
  • 6
  • 2
  • +2
1 Solution
 
MadshiCommented:
The only way I know is to recursively delete all the files and folders...   :-(
Use this function to get the path of the recycle bin:

function GetSpecialFolderPath(folder: cardinal; out path: string) : boolean;
var pidl   : PItemIDList;
    malloc : IMalloc;
begin
  path:='';
  result:=SHGetSpecialFolderLocation(INVALID_HANDLE_VALUE,folder,pidl)=NOERROR;
  if result then
    try
      SetLength(path,MAX_PATH);
      result:=SHGetPathFromIDList(pidl,pchar(path));
      if result then path:=string(pchar(result))
      else           path:='';
    finally
      if SHGetMalloc(malloc)=NOERROR then
        malloc.Free(pidl);
    end;
end;

If you have Delphi 3, then replace the "out" with "var". If you've Delphi 2 then you'll have to work a little bit at the COM objects.

Give in CSIDL_BITBUCKET as the folder. If you're interested in what paths you can get furthermore with this function look at the documentation of SHGetSpecialFolderLocation.

Regards, Madshi.
0
 
BlackManCommented:
There is a SHEmptyRecycleBin call that does the trick, I have some Delphi code somewhere, I'll try to dig it up..
0
 
MadshiCommented:
Hi BlackMan, ok, that would of course be much simpler (=better) than my suggestion...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ronit051397Commented:
SHEmptyRecycleBin is not declared in D2/D3, you need declare it, see:
http://www.takenet.or.jp/~ryuuji/delphi/download/shellapi98.pas
0
 
BlackManCommented:
Actually, my code is based on the library mentioned by ronit, so just download it and call SHEmptyRecycleBin(Application.Handle, '', 0) to empty the recycle bin.
By adding a combination of the option-constants instead on 0, you can change the behavoiur of the function...
0
 
jexd99Author Commented:
Thanks
0
 
fredff13Commented:
Madshi's comment:
I used your function under Windows NT and get False result after function SHGetPathFromIDList(pidl,pchar(path)). Is it means that path for Recycle Bin is not exist?
BlackMan's answer:
I cannot use SHEmptyRecycleBin(Application.Handle, '', 0) because Windows message shows me that my Shell32.dll doesn't have SHEmptyRecycleBinA function.
I declared in my unit
function SHEmptyRecycleBin  ; external shell32 name 'SHEmptyRecycleBinA';
Still waiting for correct expert opinion.  
0
 
MadshiCommented:
Yes, you're right! That's really strange. We get a valid pidl, but it seems to be not part of the file system. Though the recycle directory IS part of the file system. I don't get it. Well, it's Micro$~1...   :-(

However, there was one bug in my function. So if you want to use it for other things, use this corrected version:

function GetSpecialFolderPath(folder: cardinal; out path: string) : boolean;
var pidl   : PItemIDList;
    malloc : IMalloc;
begin
  path:='';
  result:=SHGetSpecialFolderLocation(Application.Handle,folder,pidl)=NOERROR;
  if result then
    try
      SetLength(path,MAX_PATH);
      result:=SHGetPathFromIDList(pidl,pchar(path));
      if result then path:=string(pchar(path))
      else           path:='';
    finally
      if SHGetMalloc(malloc)=NOERROR then
        malloc.Free(pidl);
    end;
end;

Regards, Madshi.
0
 
fredff13Commented:
I received answer from Daniel U. Thibault a.k.a. Urhixidur, that explained why it's impossible to use this function to find path for CSIDL_BITBUCKET:
"SHGetPathFromIDList will fail because the Recycle Bin exists in multiple places. Under Win95, it will have part of itself on each drive (C:\Recycled, D:\Recycled, etc.). Under WinNT, it gets
worse since it subdivides each Recycler (note the name change) directory according to the currently logged-on user. So, you can obtain the recycle bin's PIDL, but not its path."  
0
 
MadshiCommented:
Ah... Thanx for the info...   :-)
0
 
fredff13Commented:
I can't update Shell32.dll from version 4.00 to 4.71 or above even after installing IE 5.01. If you can help me please.
0
 
MadshiCommented:
What do you mean with you can't do that? Do you have the new dll version at hand? Where's the problem?
0
 
fredff13Commented:
I got mail with next suggestion how to move to Shell32 enhancement:
"Believe it or not, you'll have to *uninstall* IE5 first, then install IE4 (basic install). Once IE4 is installed, when you click Add/Remove for Microsoft Internet Explorer 4 in the "Add/Remove
Programs" control panel, you'll be presented with a small set of choices, one of which is to get the Desktop Update. That's the one you want.
Once the Desktop Update is in place, you'll be able to re-install IE5, if you must (I prefer Netscape myself).
The Desktop Update changes the behaviour of the shell in all sorts of neat ways. One way you can tell it is in place is to bring up the Start Menu and then right-click on a Start Menu item."
So, I need make changes with Desktop Update. This is too complicated for me. Is there any other ways?
0
 
MadshiCommented:
Ah, you meant not only this one little shell32.dll, but the complete IE4-system-upgrade!! That's quite a huge difference! IE4 with Desktop Update replaces large parts of the operating system. So you can almost move from win95 to win98. If you already have win98, you don't need that, but for win95 it's an interesting choice. That's right, you need to uninstall IE5 first...   :-(

Regards, Madshi.
0
 
fredff13Commented:
Unfortunately, I have Windows NT! So... And some other PCs in our office with Windows 98 have right Shell32.dll!!! I cannot just copy this file over my system.
0
 
MadshiCommented:
Well, okay, I think with NT it's the same story as with win95. IE4 will replace big parts of the user interface. So you'll have no other choice than to uninstall IE5...
0
 
fredff13Commented:
Thank's, I just wondering if I after uninstall IE 5, and than eventually IE 4 with Desktop Upadate I'm not run into the much bigger problems.
0
 
MadshiCommented:
Maybe...   :-)   :-((
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now