Solved

emptying recycle bin

Posted on 1998-12-18
18
286 Views
Last Modified: 2010-04-04
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
Comment
Question by:jexd99
  • 8
  • 6
  • 2
  • +2
18 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
There is a SHEmptyRecycleBin call that does the trick, I have some Delphi code somewhere, I'll try to dig it up..
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Hi BlackMan, ok, that would of course be much simpler (=better) than my suggestion...
0
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
SHEmptyRecycleBin is not declared in D2/D3, you need declare it, see:
http://www.takenet.or.jp/~ryuuji/delphi/download/shellapi98.pas
0
 
LVL 7

Accepted Solution

by:
BlackMan earned 50 total points
Comment Utility
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
 

Author Comment

by:jexd99
Comment Utility
Thanks
0
 

Expert Comment

by:fredff13
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 

Expert Comment

by:fredff13
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Ah... Thanx for the info...   :-)
0
 

Expert Comment

by:fredff13
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
What do you mean with you can't do that? Do you have the new dll version at hand? Where's the problem?
0
 

Expert Comment

by:fredff13
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 

Expert Comment

by:fredff13
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
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
 

Expert Comment

by:fredff13
Comment Utility
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
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Maybe...   :-)   :-((
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now