Solved

emptying recycle bin

Posted on 1998-12-18
18
289 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 10 Seattle Dataset Actions 5 79
Run video youtube webbrowse 10 57
TEMBEDDEDWB how can i change its user agent ? 8 47
How to load 2 images in same column in Delphi 2 33
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

21 Experts available now in Live!

Get 1:1 Help Now