Solved

emptying recycle bin

Posted on 1998-12-18
18
293 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
ID: 1351926
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
ID: 1351927
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
ID: 1351928
Hi BlackMan, ok, that would of course be much simpler (=better) than my suggestion...
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 5

Expert Comment

by:ronit051397
ID: 1351929
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
ID: 1351930
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
ID: 1351931
Thanks
0
 

Expert Comment

by:fredff13
ID: 2281146
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
ID: 2282577
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
ID: 2283537
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
 
LVL 20

Expert Comment

by:Madshi
ID: 2283675
Ah... Thanx for the info...   :-)
0
 

Expert Comment

by:fredff13
ID: 2284366
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
ID: 2285814
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
ID: 2286856
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
ID: 2286939
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
ID: 2286969
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
ID: 2287025
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
ID: 2287141
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
ID: 2287279
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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